julzk Posted December 24, 2009 Share Posted December 24, 2009 Hi, I am wanting to Calculate Hours & Minutes between two Dates/Time. I have four fields: ss_datestart, ss_dateend and ss_timestart and ss_timeend. I want to display the hours and minutes between two dates/times. Example: $ss_datestart $ss_timestart --- $ss_dateend $ss_timeend 05-12-2009 13:44:31 --- 05-12-2009 17:55:31 I want it to then display the difference in hours and minutes only, so it would return: 04h 11m (ignoring the seconds of course). And if it were something that went over a day so: 05-12-2009 13:44:31 --- 06-12-2009 17:55:31 <--- This would return: 28h 11m FYI: Dates are dd-mm-yyyy Link to comment https://forums.phpfreaks.com/topic/186203-calculate-hours-minutes-between-two-datestime/ Share on other sites More sharing options...
p2grace Posted December 24, 2009 Share Posted December 24, 2009 There might be an easier way, but something like this should do the trick off the top of my head. <?php $day1 = "05-12-2009 13:44:31"; $day2 = "05-12-2009 17:55:31"; $result = strtotime($day1) - strtotime($day2); $diff = $result / 31556926; $h = date("h",$diff); $i = date("i",$diff); $h = (substr($h,0,1) == 0) ? substr($h,1) : $h; $i = (substr($i,0,1) == 0) ? substr($i,1) : $i; echo "$h hours $i minutes"; ?> Link to comment https://forums.phpfreaks.com/topic/186203-calculate-hours-minutes-between-two-datestime/#findComment-983390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.