|
Posted by Ken Robinson on 12/15/05 16:34
Simon Dean wrote (in part):
> Probably being a little thick here, but when you subtract one date away
> from another, how do you convert the resultant value into a number of
> days... I guess I could easily / 60 / 60 / 24... but that seems
> barbaric... Anything neater?
This the simpliest function I could come up with for getting the
difference between two dates. Note that I didn't code any error
checking.
<?php
echo date_diff ("20051210", "20051230");
function date_diff($s,$e)
{
return((strtotime($e) - strtotime($s))/86400);
}
?>
Since the strtotime() function returns the number of seconds since
1/1/1970, you need to divide the result by the number of seconds in a
day (86400) to get the number of days.
Ken
Navigation:
[Reply to this message]
|