|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-01-04 13:51 UTC] keloran at develbox dot info
Description:
------------
If you do the test, you should get if today is
02/01/2012
the result should be
03/01/2011
but instead you get
02/01/2011
Test script:
---------------
echo date("d/m/Y", strtotime("yesterday last year"));
Expected result:
----------------
03/01/2011
Actual result:
--------------
02/01/2011
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 23:00:02 2025 UTC |
To add to this... date('n', strtotime('+ 1 month', time())); That should be 2 and it is returning a 3. Now it is 3:30 PM EST when i noticed this, so by using a preset timestamp you can reproduce this. date('n', strtotime('+ 1 month', '1327954976')); Will return 3 instead of 2 as well. I am guessing this will never be fixed, and if not, maybe say "hey, we cant fix this one" -OR "this is more work to fix than it is worth" instead of ignoring the problem? https://bugs.php.net/bug.php?id=27793 that is from 2004!!! Not to mention there is a note at the bottom of it that it was posted at least 5 other times.Keloran, your bug report is confusing with respect to day/month order. I am assuming you mean m/d when you say 02/01 and 03/01 but your script says d/m/Y. Please provide an actual script with a timestamp baked in. Like this: echo date("d/m/Y H:i:s\n",1328126500); echo date("d/m/Y\n", strtotime("yesterday last year",1328126500)); That outputs: 01/02/2012 12:01:40 31/01/2011 which looks completely correct to me. Austin, yours is not a bug. When you add a month to Jan.30 it goes to Feb.30 which doesn't exist. So it adjusts it to Mar.1. strtotime follows the standard UNIX date addition behaviour in this. From your Linux command line try this: % date Mon Jan 30 17:49:22 EST 2012 % date --date='+1 month' +'Next month is %B' Next month is March You can find this behaviour documented here: http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date- strings.html#SEC125<?php $preData = 1327928400; $a = strtotime("last monday", $preDate); $b = strtotime("last year last monday", $a); $c = date("d/m/Y H:i:s", $a); $d = date("d/m/Y H:i:s", $b); print_r(array( "PreDate" => $preDate, "Today Time" => $a, "Last Year Time" => $b, "Converted Today" => $c, "Converted Last Year" => $d, ));Array ( [PreDate] => 1327928400 [Today Time] => 1327842000 [Last Year Time] => 1295701200 [Converted Today] => 30/01/2012 00:00:00 [Converted Last Year] => 23/01/2011 00:00:00 )