php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63970 Wrong year on week calculation from 2012-12-30
Submitted: 2013-01-11 16:31 UTC Modified: 2013-01-12 09:21 UTC
From: obibann at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.20 OS: RedHat EL 6.2
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: obibann at hotmail dot com
New email:
PHP Version: OS:

 

 [2013-01-11 16:31 UTC] obibann at hotmail dot com
Description:
------------
Set your server on December 30 2012:

date -s "20121230 11:00"

Ask PHP to give you the year and week 52 weeks ago thanks to the code below.
PHP prints "201252" instead of "201201"
No problems from other dates of with another value of week.

Test script:
---------------
date_default_timezone_set("Your/Timezone"); // For me Europe/Paris
echo date("YW",strtotime("-52 week"));

Expected result:
----------------
201201

Actual result:
--------------
201252

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-11 16:34 UTC] obibann at hotmail dot com
Erratum :

I think it should return "201152"
 [2013-01-11 16:51 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-01-11 16:51 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

This is not a bug. "Y" is the real year, where as "o" is the ISO year. The "W" denotes the "ISO Week number" which ties in into the "ISO Year". Please refer to http://en.wikipedia.org/wiki/ISO_week for the back story.

When you run your script with "o" instead of "Y", the answer is the correct "201152":

<?php
date_default_timezone_set("Europe/Paris");
echo date("o-W",strtotime("2012-12-30 11:00 -52 week")), "\n";
?>

Shows:

2011-52
 [2013-01-12 09:21 UTC] obibann at hotmail dot com
Great !
Thank you very much for this explaination.

Regards
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 09 22:01:33 2024 UTC