note 106447 added to datetime.diff
| From: | astagl at gmail dot com | Date: | Thu, 10 Nov 2011 04:21:38 +0000 |
| Subject: | note 106447 added to datetime.diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184362@lists.php.net to get a copy of this message | ||
I needed to get the exact number of days between 2 dates and was relying on the this diff function,
but found that I was getting a peculiar result with:
<?php
$today = new DateTime(date('2011-11-09'));
$appt = new DateTime(date('2011-12-09'));
$days_until_appt = $appt->diff($today)->d;
?>
This was returning 0 because it was exactly one month.
I had to end up using :
<?php
$days_until_appt = $appt->diff($today)->days;
?>
to get 30.
----
Server IP: 69.147.83.197
Probable Submitter: 71.239.145.221
----
Manual Page -- http://www.php.net/manual/en/datetime.diff.php
Edit -- https://master.php.net/note/edit/106447
Del: integrated -- https://master.php.net/note/delete/106447/integrated
Del: useless -- https://master.php.net/note/delete/106447/useless
Del: bad code -- https://master.php.net/note/delete/106447/bad+code
Del: spam -- https://master.php.net/note/delete/106447/spam
Del: non-english -- https://master.php.net/note/delete/106447/non-english
Del: in docs -- https://master.php.net/note/delete/106447/in+docs
Del: other reasons-- https://master.php.net/note/delete/106447
Reject -- https://master.php.net/note/reject/106447
Search -- https://master.php.net/manage/user-notes.php