#50048 [Opn->Bgs]: Strtotime Last fails
| From: | rasmus@php.net | Date: | Mon, 02 Nov 2009 07:19:52 +0000 |
| Subject: | #50048 [Opn->Bgs]: Strtotime Last fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144152@lists.php.net to get a copy of this message | ||
ID: 50048
Updated by: rasmus@php.net
Reported By: arnbme at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Date/time related
Operating System: Wamp or Linux
PHP Version: 5.3.0
New Comment:
No, in common English usage, when you just say "last Sunday" it means
the previous Sunday.
eg. "Where were you last Sunday?"
You have to be explicit and say:
"What date is the last Sunday of November?"
Then the English makes sense, and if you try that with strtotime() you
will find that it works.
eg. strtotime("last Sunday of November")
Previous Comments:
------------------------------------------------------------------------
[2009-11-02 01:14:01] arnbme at gmail dot com
It would seem my interpretation of "last" varies from the one used by
PHP strtotime. I assumed "last Sunday" means the last date that was a
Sunday in the month specified by now, similar to how "4 Sunday" moves
forward in time, however PHP strtotme apparently interprets "last" to
mean "prior" in which case it is operating as designed.
Example 1 for strtotime does not show any results. If documentation for
using last with strtotime is available please post a link.
------------------------------------------------------------------------
[2009-11-01 20:00:28] sjoerd@php.net
Thank you for your bug report.
Your example prints the last Sunday for December 1st, 2009. The Sunday
before that date is November 29th. Can you explain why you think the
output is wrong? Also, could you provide a shorter reproduce script,
like this:
<?php
$now = strtotime('2009-12-01');
echo date('c', strtotime('last Sunday', $now))."\n";
?>
------------------------------------------------------------------------
[2009-11-01 14:12:20] arnbme at gmail dot com
Description:
------------
the last option of strtotime seems to ignore the int $now parameter.
Reproduce code:
---------------
<?php
$br='<br>';
$mths =
array("","January","February","March","April","May","June","July","August","September","October","November","December");
$x = strtotime('2009-11-29'); //date to age
$Year = date("Y",$x);
$Month = date("m",$x);
if ($Month == 12){
$Year++;
$Month = 1;}
else
$Month++;
$n=strtotime($mths[$Month].' 01, '.$Year);
echo 'base date:',date("Y-m-d",$n),$br;
if ($n==false)
die ('bad date');
$nextdt=date( "Y-m-d",strtotime("last Sunday", $n));
echo 'Calc Last:',$nextdt,$br; //result is 2009-11-29 should be
2009-12-27
?>
Expected result:
----------------
Should show 2009-12-27
Actual result:
--------------
2009-11-29
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50048&edit=1