php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63929 wrong year in strtotime
Submitted: 2013-01-07 10:21 UTC Modified: 2013-01-07 15:37 UTC
From: daniz at rocketmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniz at rocketmail dot com
New email:
PHP Version: OS:

 

 [2013-01-07 10:21 UTC] daniz at rocketmail dot com
Description:
------------
Year is wrong in result based on test.


Test script:
---------------
$date = "2013-01-07";
echo date('W Y', strtotime("-1 week", strtotime($date)));

Expected result:
----------------
Should be "01 2013"


Actual result:
--------------
Result is "01 2012"


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-07 12:43 UTC] r07271368 at hotmail dot com
Please try this:

$date = "2013-01-07";
$earlier = strtotime("-1 week", strtotime($date));
// should result in 31 Dec 2012, which is a Monday
echo date('r', $earlier); // to make sure we have the right date
echo "\n";
echo date('W Y', $earlier); // what you have
echo "\n";
echo date('W o', $earlier); // what I think you want
echo "\n";

I ran it and got this:

Mon, 31 Dec 2012 00:00:00 +0000
01 2012
01 2013
 [2013-01-07 13:11 UTC] daniz at rocketmaik dot com
Indeed you're assumption is correct.
Reading the info regarding the 'o' gives meening why I'm seeing what I'm seeing.

Thanks
 [2013-01-07 15:37 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

As the other commenter said, for the ISO Year, you need the "o".
 [2013-01-07 15:37 UTC] derick@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 05:01:28 2024 UTC