Jump to content

Display Day, Hour, Minute Time Difference


SalientAnimal

Recommended Posts

Hi All,

 

Again I have a very simple question. I would like to show the TAT of a particular item in the format of DD:HH:MM. The creation date is stored in my database as a TIMESTAMP and the time difference is calculated on the current time.

 

Here is what I have at the moment:

, TIMESTAMPDIFF(HOUR,sys_date,NOW()) AS current_tat

 

I tried

, TIMESTAMPDIFF(DAY, HOUR, MINUTE,sys_date,NOW()) AS current_tat

which did not work and also other simplar variations. What is the corect way to do this please?

 

Thanks

Link to comment
Share on other sites

you could do this as a compromise

SELECT
TIMESTAMPDIFF(DAY,'2012-06-22 16:00:00', NOW()) as dayportion,
SEC_TO_TIME(TIMESTAMPDIFF(SECOND,'2012-06-22 16:00:00', NOW()) MOD 86400) as timeportion

 

result-->

+------------+-------------+
| dayportion | timeportion |
+------------+-------------+
|          2 | 18:35:12    |
+------------+-------------+

 

edit:

NOW() is approx 2012-06-25 10:37:11

Link to comment
Share on other sites

Thanks :)

 

Just for my understanding, as I don't jsut want to plug and play the code, what exactly does the MOD 86400 do?

 

I know the 86400 is a representation of 3600 minutes in a day ,etc...

 

Also I am using a system generated date, and not a predefined date as you have captured, hopefully this won't effect the results?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.