Bug #68195 [Nab]: Issue with day number / name in a week
| From: | sandro dot casa at gmail dot com | Date: | Thu, 09 Oct 2014 08:30:13 +0000 |
| Subject: | Bug #68195 [Nab]: Issue with day number / name in a week | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187975@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68195&edit=1
ID: 68195
User updated by: sandro dot casa at gmail dot com
Reported by: sandro dot casa at gmail dot com
Summary: Issue with day number / name in a week
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Windows NT SCA 6.1 build 7601 (W
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Dear Guru,
thanks a ton for the workarround with the DateTime() function,
you saved my day.
Regards,
Sandro
Previous Comments:
------------------------------------------------------------------------
[2014-10-09 08:18:48] 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 07:55:06] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68195&edit=1