Jump to content

Calculate Datetime difference


bjory

Recommended Posts

Hi,

I wannna calculate the difference in hours from 2 datetime strings e.g. [color=red]10/08/2006 11:00:00 [/color] and [color=red]10/02/2006 12:00:00[/color]. As these strings are varchars in the database, I hope someone can give me some clues how I can calculate the hours and min difference between these 2 strings.

Thanks!
Link to comment
https://forums.phpfreaks.com/topic/27926-calculate-datetime-difference/
Share on other sites

[code]$time1 = strtotime("10/08/2006 11:00:00");
$time2 = strtotime("10/02/2006 12:00:00");

echo round(($time1 - $time2) / 86400, 2) . " Days Between Dates";[/code]

Adjust the division (the 86400) for different time spans to get hours and so on.  You could also break it out to days, hours, minutes, seconds by dividing and taking the remainder if you wanted.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.