|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
There seem to be alot of ways to perform date subtraction but one way that I do not see in the documentation or posts is this:
I have a date in the future (TIMESTAMP1). I want to find out how many days,hours,minutes,seconds between NOW() and TIMESTAMP1. All of the functions I have seen deal with either the difference in seconds, or formating a new date from the calculation. I am trying to get "countdown" information I guess you could call it, that says "x days, y hours, z minutes until TIMESTAMP. If I have missed something obvious, my apologies, but any help would be greatly appreciated. Thanks, kp |
|
#2
|
|||
|
|||
|
The best idea I could come up with is to convert to a unix timestamp to get a difference in seconds. You would have to convert to ddhhmmss format from that.
select unix_timestamp(date_field)-unix_timestamp() as sec_diff from table; |
|
#3
|
|||
|
|||
|
Okay, that is something that I had considered but what is the best way to do the conversion to d:m:h:s afterwards?
|
|
#4
|
|||
|
|||
|
$days=intval($timediff/86400);
$remain=$timediff%86400; $hours=intval($remain/3600); $remain=$remain%3600; $mins=intval($remain/60); $secs=$remain%60; print "$days:$hours:$mins:$secs"; |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > computing d:h:m:s difference between two dates |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|