php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28594 strtotime bug
Submitted: 2004-05-31 23:17 UTC Modified: 2004-06-03 16:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tavancini at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.6 OS: Windows 2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tavancini at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-05-31 23:17 UTC] tavancini at hotmail dot com
Description:
------------
strtotime not calculating actual date subtraction

Reproduce code:
---------------
<?
echo date( "m/Y", strtotime("-11 month") ) . "<br><br>";
echo date( "m/Y", strtotime("-10 month") ) . "<br><br>";
?>

Expected result:
----------------
07/2003
08/2003

Actual result:
--------------
07/2003
07/2003

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-01 07:30 UTC] jed at jed dot bz
Better demonstration:

for($x = 12; $x >= 1; $x--)
    echo date("m/Y", strtotime(sprintf("$x month%s ago",
        $x == 1 ? '' : 's'))) . "\n";

Odd assortment of dates.
 [2004-06-01 08:19 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.

Works for me, come up with a better script which also takes care of timezones etc.
 [2004-06-01 18:30 UTC] tavancini at hotmail dot com
Hi,

The script is the same as I posted.

Only a comment, when i change the server date to May 30, or, May 31.. the script goes crazy and reproduce the error as i mentioned.

BUT, today, June 1st, the script goes normally as i programmed.

Strange thing...

for information, i am using...
English Windows 2000 Server - Service Pack 3
Locale "Portugues (Brazil)
Short Date Format "d/M/yyyy"
(GMT -03:00) - Brasilia

Thanks.
 [2004-06-02 11:39 UTC] mgf@php.net
H'mm, let's see, on 31-May:

-11months = 31-June, which doesn't exist so is treated as 01-July
-10months = 31-July (fine)
-9 months = 31-August (fine)
-8 months = 31-September (doesn't exist, treat as 01-Oct)
-7 months = 31-October (fine)
-6 months = 31-November (doesn't exist, treat as 01-Dec)

etc.

Not a PHP bug.
 [2004-06-02 11:41 UTC] mgf@php.net
Woops, really setting Bogus.
 [2004-06-02 17:08 UTC] tavancini at hotmail dot com
No... No,

-11 month = 07-2003
-10 month = 07-2003

got it?
 [2004-06-02 17:57 UTC] pollita@php.net
Yes... Yes,

-11 month = 06-31-2003 => 07-01-2003 => 07-2003
-10 month = 07-31-2003 =>               07-2003

got it?

 [2004-06-02 18:58 UTC] tavancini at hotmail dot com
so, this is not a bug??

if it is not, how can i make my code to function proberly?
i only need to calculate the months...

thanks
 [2004-06-03 16:00 UTC] mgf@php.net
This has now become a support query, which should be directed to php-general@lists.php.net.  (However, I suggest you look at mktime(), and using a day number which occurs in every month.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 08:01:29 2024 UTC