bjory Posted November 21, 2006 Share Posted November 21, 2006 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 More sharing options...
hitman6003 Posted November 21, 2006 Share Posted November 21, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/27926-calculate-datetime-difference/#findComment-127715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.