So, heres a function to count the days between two dates. Its pretty easy to understand and very easy to use.
Ive added a few comments but its important to know, the strtotime function
only works on american dates, eg: MM/DD/YY and NOT DD/MM/YY like us English use...
function count_days($a, $b)
{
//Convert times to string format//
$datea = strtotime($a);
$dateb = strtotime($b);
//Use getdate on the strings (explodes them into array form//
//See manual for specific array column names//
$a_dt = getdate($datea);
$b_dt = getdate($dateb);
//Uses maketime to generate a numeric value for the date//
//Ive used 12, 0, 0 to specify midday every day (Using a constant time value)//
$a_new = mktime(12,0 ,0, $a_dt['mon'], $a_dt['mday'], $a_dt['year']);
$b_new = mktime(12,0 ,0, $b_dt['mon'], $b_dt['mday'], $b_dt['year']);
//Returns a rounded value devided by number of seconds in the day//
return round(($a_new - $b_new) / 86400);
}
Hope its of some use to someone.
Regards
Ollie
Posted by OLLIE at 18:39pm
No comments yet. Be the first to add one!