php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43849 date('YW', strtotime('2007-12-31')) return 200701
Submitted: 2008-01-15 06:18 UTC Modified: 2008-01-15 07:12 UTC
From: kiange at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.5 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kiange at gmail dot com
New email:
PHP Version: OS:

 

 [2008-01-15 06:18 UTC] kiange at gmail dot com
Description:
------------
Enviornments:
PHP 5.2.3-1ubuntu6.2

Reproduce code:
---------------
echo date('YW', strtotime('2007-12-31'));
// return 200701, maybe 200801 according to the reference page
echo strftime("%Y%W",strtotime("2007-12-31"));
// return 200753

Expected result:
----------------
200753 or 200801

Actual result:
--------------
200701

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-15 07:12 UTC] derick@php.net
This is correct, the "W" shows the ISO week, which you need to match against the ISO year specifier ("o" - small "O"). ISO Week 2008-01 goes from Dec 31st to Jan 6th. This will return what you expect:

echo date('Yo', strtotime('2007-12-31')), "\n";

strftime() would not be good to rely on, as the output might differ on other operating systems.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 13:01:34 2025 UTC