php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60176 date + strtotime fails to calculate date
Submitted: 2011-10-31 00:20 UTC Modified: 2011-10-31 15:45 UTC
From: sombra2eternity at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4 OS: Ubuntu
Private report: No CVE-ID: None
 [2011-10-31 00:20 UTC] sombra2eternity at gmail dot com
Description:
------------
Dont know if corrected in new versions but I cant actually upgrade so I write it here anyway to be sure its reported.

Strtotime/date fails to get the date in a simple test.

I think I found a bug:

echo date("Y-m-d",strtotime('2011-10-30')+86400);
//returns 2011-10-30 and should return 2011-10-31

desktop7@desktop7-desktop:~$ php -v
PHP 5.3.5-1ubuntu7.3 with Suhosin-Patch (cli) (built: Oct 13 2011 21:56:07) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Test script:
---------------
echo date("Y-m-d",strtotime('2011-10-30')+86400);

Expected result:
----------------
2011-10-31

Actual result:
--------------
2011-10-30

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-31 14:01 UTC] fa@php.net
-Status: Open +Status: Feedback
 [2011-10-31 14:01 UTC] fa@php.net
I can't reproduce this with PHP_5_3 HEAD.

Could you please check that your "date.timezone" is set correctly in your php.ini?

It could help to compare "Y-m-d H:i:s" output.
 [2011-10-31 14:37 UTC] sombra2eternity at gmail dot com
I just compiled: php5.4-201110311230

-------------------
desktop7@desktop7-desktop:~/php5.4-201110311230/sapi/cli$ ./php -v
PHP 5.4.0RC1-dev (cli) (built: Oct 31 2011 15:21:08) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2011 Zend Technologies
-------------------

desktop7@desktop7-desktop:~/php5.4-201110311230/sapi/cli$ ./php /var/www/strto.php
2011-10-30

CONTENT OF STRTO.PHP:
<?php
date_default_timezone_set('Europe/Madrid');
echo date('Y-m-d',strtotime('2011-10-30')+86400);
?>

Thanks for helping me
 [2011-10-31 14:37 UTC] sombra2eternity at gmail dot com
-Status: Feedback +Status: Open -PHP Version: 5.3.8 +PHP Version: 5.4
 [2011-10-31 15:45 UTC] fa@php.net
We are happy to tell you that you just discovered Daylight Savings
Time. For more information see:
http://webexhibits.org/daylightsaving/b.html
Instead of using mktime/date consider using gmmktime and gmdate which do
not suffer from DST.

You do realize that there are indeed 24h between 2011-10-30 00:00:00 and 2011-10-30 23:00:00, right?

This is when DST was adjusted.

Try your code with 2011-10-31 and you'll see 2011-11-01 as a result of adding 24h.
 [2011-10-31 15:45 UTC] fa@php.net
-Status: Open +Status: Bogus
 [2011-11-14 15:08 UTC] sombra2eternity at gmail dot com
@fa

You are totally right. My fault, sorry for the noise.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC