I rewrote the datediff function in the submission tracker and thought PHP geeks might enjoy it. I find it very sad that PHP does not have a built-in datediff function like ASP or Cold Fusion.
/*The variable $date1 comes from the database, and is converted to unix timestamp format. This is a mySQL date, not a datetime. */
$date1 = strtotime($col_value.” GMT”);
/*The variable date2 is today converted to unix timestamp format.*/
$date2 = strtotime(date(“m/d/y”).” GMT”);
/*Subtract database date from today to get number of days story has been out in unix timestamp format.*/
$daysdiff = ($date2 – $date1);
/*Convert number of days story has been out in unix timestamp format to seconds since the beginning of the unix epoch and divide by 86400, or the number of seconds in a day. This should be a round number, since we started with dates, not datetimes. */
$datediff = (date(“U”, $daysdiff)/86400)
I used to instead convert to dayofyear, but that only worked for time periods that were less than a year.