php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66963 Same code returns different results after php update
Submitted: 2014-03-26 22:52 UTC Modified: 2014-03-28 19:27 UTC
From: pedro dot bicudo at tgtconsult dot com dot br Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Linux CentOS 6
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: pedro dot bicudo at tgtconsult dot com dot br
New email:
PHP Version: OS:

 

 [2014-03-26 22:52 UTC] pedro dot bicudo at tgtconsult dot com dot br
Description:
------------
Using amazon-linux-ami/2013.09; Linux 3.4.48-45.46.amzn1.x86_64 on x86_64. Date shown for user is wrong. To isolate any database error during test, I've created the date with php and then show the timestamp. Different versions of php show different results. Version 5.3.28 is the latest PHP available for his AWS instance. Apache 2.2.26.

Test script:
---------------
$date=date_create("2014-01-01");echo date_timestamp_get($date);
$date=date_create("2014-06-14");echo date_timestamp_get($date);

Expected result:
----------------
For date 2014-01-01:
php 5.3.26 returns 1388534400 (correct result)
php 5.3.28 returns 1388541600

For date 2014-01-01:
php 5.3.26 returns 1402704000 (correct result)
php 5.3.28 returns 1402714800


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-26 22:57 UTC] aharvey@php.net
-Status: Open +Status: Feedback -Package: Built-in web server +Package: Date/time related
 [2014-03-26 22:57 UTC] aharvey@php.net
Are you sure that each PHP version is running with the same default time zone set? You can check that by calling date_default_timezone_get().
 [2014-03-27 00:57 UTC] pedro dot bicudo at tgtconsult dot com dot br
-Status: Feedback +Status: Open
 [2014-03-27 00:57 UTC] pedro dot bicudo at tgtconsult dot com dot br
Yes, same timezone.Changing timezones did not change the results.
 [2014-03-27 01:41 UTC] pedro dot bicudo at tgtconsult dot com dot br
aharvey, I double checked and found different timezones (UTC and Americas/Sao_Paulo), new problem now, from the test script posted: for date 2014-01-01 difference is 7200 seconds (2hours) and for date 2014-06-14 difference is 10800s (3hours). Daylight savings? Can you point me to the documentation of how time gets calculated by PHP?
 [2014-03-28 18:24 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2014-03-28 18:24 UTC] johannes@php.net
Times are calculated based on the Olson database which is maintained by IANA. We bundle always the at release time current version. Youcan figure out which version is being used from phpinfo() in the field ""Olson" Timezone Database Version" under "date" or by using the timezone_version_get() function.

See http://www.iana.org/time-zones for information from IANA.
 [2014-03-28 19:27 UTC] pedro dot bicudo at tgtconsult dot com dot br
Thanks aharvey and johannes. Although this is not a bug, I have a problem when converting dates from Excel to Unix (just subtract 25569 and multiply by 86400 to get Unix timestamp), then save to a database. Unix timestamp does not consider timezones. When accessed by a web application, PHP takes the timestamp saved in the database and converts to day/month considering server's timezone, most likely not the timezone of the person who provided the Excel number, and who is reading the day/month provided by PHP. Day shown by PHP differs from the day provided by upload, plus or minus 1, because of the timezone configured in php.ini. Workaround is to set php.ini timezone to UTC when you need to convert dates from other systems. (I do not know you to close this ticket, consider solved. If someone can add this to php documentation would be of great help)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC