php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68195 Issue with day number / name in a week
Submitted: 2014-10-09 07:55 UTC Modified: 2014-10-09 08:30 UTC
From: sandro dot casa at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Windows NT SCA 6.1 build 7601 (W
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: sandro dot casa at gmail dot com
New email:
PHP Version: OS:

 

 [2014-10-09 07:55 UTC] sandro dot casa at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.date
---
l (lowercase 'L'): A full textual representation of the day of the week	Sunday through Saturday

N ISO-8601:  numeric representation of the day of the week (added in PHP 5.1.0)	1 (for Monday) through 7 (for Sunday)

My PHP version is 5.5.6

Test script:
---------------
// My PHP version is 5.5.6
$date = '1900-01-01';
echo date('N', strtotime($date));    // ==> 4      
echo date('l', strtotime($date));    // ==> Thurday

The thing is the 1st of Jan 1900 was a Monday...

Expected result:
----------------
$date = '1900-01-01';
echo date('N', strtotime($date));    // ==> 1      
echo date('l', strtotime($date));    // ==> Monday


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-09 08:18 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: Calendar related +Package: Date/time related
 [2014-10-09 08:18 UTC] requinix@php.net
Unless you're running one of the experimental builds of PHP x64 for Windows (and probably not even then), your PHP cannot handle 1900 as a Unix timestamp. It's too far in the past for a 32-bit number.
strtotime() will fail, which means it will return false, which is basically 0, which corresponds to 1970-01-01. Try it:
  echo date('r', strtotime($date));

Fortunately, DateTime works differently.
  $date = new DateTime('1900-01-01');
  echo $date->format('N'); // 1
  echo $date->format('l'); // Monday
 [2014-10-09 08:30 UTC] sandro dot casa at gmail dot com
Dear Guru,

thanks a ton for the workarround with the DateTime() function, 
you saved my day.

Regards,

Sandro
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 04:00:01 2026 UTC