Hey, I need something that checks the difference between two times. The format of the times is: Apr 26, 2009 1:42 PM Apr 26, 2009 5:44 PM It would subtract those and then output the difference in minutes. For example the times above would output 242 minutes. It also needs to check for the dates too.
You could easily use strtotime. It lots of formats and returns the unix timestamp representation of it. $timeA = strtotime("Apr 26, 2009 1:42 PM"); $timeB = strtotime("Apr 26, 2009 5:44 PM"); $minutes = ceil(($timeB - $timeA) / 60); echo $minutes; PHP:
The easiest way would be $time1 = 'Apr 26, 2009 1:42 PM'; $time2 = 'Apr 26, 2009 5:44 PM'; $total = $time1 - $time2; echo $total; PHP:
I got it working with a big chunk of code. I'll give the first one a try but I know the second one won't work at all. Please don't post stupid stuff if you really have no clue what you're talking about.
function duration($start,$end) { $seconds = ($end - $start); $days = floor($seconds/60/60/24); $hours = $seconds/60/60%24; $mins = $seconds/60%60; $secs = $seconds%60; $duration=''; if($days>0) $duration .= "$days days "; if($hours>0) $duration .= "$hours hours "; if($mins>0) $duration .= "$mins minutes "; if($secs>0) $duration .= "$secs seconds "; $duration = trim($duration); if($duration==null) $duration = '0 seconds'; return $duration; } $duration = duration($date1_stamp,$date2_stamp); PHP: define date1_stamp and date2_stamp, you can do it by converting the dates into unix stamp by strtotime function I hope this helps