Bug #66963 [Nab]: Same code returns different results after php update
| From: | pedro dot bicudo at tgtconsult dot com dot br | Date: | Fri, 28 Mar 2014 19:27:40 +0000 |
| Subject: | Bug #66963 [Nab]: Same code returns different results after php update | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184950@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66963&edit=1
ID: 66963
User updated by: pedro dot bicudo at tgtconsult dot com dot br
Reported by: pedro dot bicudo at tgtconsult dot com dot br
Summary: Same code returns different results after php update
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Linux CentOS 6
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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)
Previous Comments:
------------------------------------------------------------------------
[2014-03-28 18:24:32] 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-27 01:41:46] 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-27 00:57:31] pedro dot bicudo at tgtconsult dot com dot br
Yes, same timezone.Changing timezones did not change the results.
------------------------------------------------------------------------
[2014-03-26 22:57:32] 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-26 22:52:54] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66963&edit=1