note 101971 added to function.date-diff
| From: | joe at golike dot com | Date: | Thu, 20 Jan 2011 19:44:33 +0000 |
| Subject: | note 101971 added to function.date-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175948@lists.php.net to get a copy of this message | ||
I use this much simpler solution:
function dateDifference($firstDate, $lastDate) {
$firstTime = strtotime($firstDate);
$lastTime = strtotime($lastDate);
$diff = round(($lastTime - $firstTime) / 86400);
return $diff;
}
I've tested this using all of the cases I could think of:
- dates inside DST
- dates outside DST
- dates overlapping the start of DST
- dates overlapping the end of DST
- dates during a leap year
- dates during a non-leap year
Am I missing something that the other more complicated solutions are accounting for?
----
Server IP: 69.147.83.197
Probable Submitter: 98.210.216.87
----
Manual Page -- http://www.php.net/manual/en/function.date-diff.php
Edit -- https://master.php.net/note/edit/101971
Del: integrated -- https://master.php.net/note/delete/101971/integrated
Del: useless -- https://master.php.net/note/delete/101971/useless
Del: bad code -- https://master.php.net/note/delete/101971/bad+code
Del: spam -- https://master.php.net/note/delete/101971/spam
Del: non-english -- https://master.php.net/note/delete/101971/non-english
Del: in docs -- https://master.php.net/note/delete/101971/in+docs
Del: other reasons-- https://master.php.net/note/delete/101971
Reject -- https://master.php.net/note/reject/101971
Search -- https://master.php.net/manage/user-notes.php