[snip] Does anyone know if there is a date difference function in php? I have searched the manual but found none. What im after is a function that will return the number of days or seconds between a start date and a second date. Much like DATEDIFF in ms sql. Any help or pointing to relevant docs would be greatly appreciated. [/snip]
Going to http://www.php.net/date and searching the page for datediff revealed a function written by a member of the PHP community. Here is that post; matthijs at schoolnews dot nl 18-May-2003 06:59 I first used the VERY easy way to calculate date differences, but since I had to calculate 250+ differences, the execution time exceeded 30 seconds cause of all the loops. So I added a few improvements to fasten up the function, no more loops :) <? function dateDiff($row){ $s = $row["nu"] - $row["lastpost"]; $m = intval($s/60); $s = $s % 60; $h = intval($m/60); $m = $m % 60; $d = intval($h/24); $h = $h % 24; $diff = ""; if ( !$d == "0" ) { $diff = $diff . "$d days "; } if ( !$h == "0" ) { $diff = $diff . "$h hours "; } if ( !$m == "0" ) { $diff = $diff . "$m minutes "; } if ( !$s == "0" ) { $diff = $diff . "$s seconds "; } if ( $diff == "" ) { $diff = "-"; } trim ($diff); return $diff; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php