Solved

One server converts epoch time incorrectly

Posted on 2013-01-18
8
641 Views
Last Modified: 2013-01-18
Hi Experts,

We are having a VERY strange problem. One of our linux servers is converting epoch time into date incorrectly. It keeps being one day out.

For instance, 1364508000 converts correctly to 29 March 2013 on all of our servers, which is correct and is good Friday, but on our ONE server it converts to 28 March 2013. This is happening with all epoch stamps. It keeps converting to a day early. We are an office full of PHP developers and we are all stumped. I'm sure that this is problem on the linux server, but our linux administrator is being a little bitch, so now we have to try and fix it ourselves. ANY advice would be greatly appreciated.

Thank you in advance,
The entire Intoweb Team
0
Comment
Question by:Intoweb
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38792066
Check and compare the timezone settings on your servers.

echo $TZ

date +%Z
date +%z
0
 
LVL 4

Expert Comment

by:DanielSV
ID: 38792099
If the timezone is wrong, as woolmilkporc suggests, fix it like this.

CentOS, RedHat, etc.
sudo ln -sf /usr/share/zoneinfo/Continent/City /etc/timezone

Debian, Ubuntu, etc
sudo dpkg-reconfigure tzdata
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38792113
Where are you seeing this error?
0
 

Author Comment

by:Intoweb
ID: 38792201
I am getting this error in all my PHP scripts where we run date("Y-m-d", $iTimestamp).

The timezones are correct, although the one was on GMT +2 and the other on UCT +0, but technically it's the same time. We changed them both to GMT +2 and I'm still getting this issue.

I also don't understand how timezone would have an impact on epoch conversion. It's supposed to calculate from 0:00 01/01/1970 regardless of the timezone....

I could understand if date("U") gave different epoch's due to timezone, but once the epoch has been established, how can it be that it calculated the date wrong based on that stamp?
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38792241
<< I also don't understand how timezone would have an impact on epoch conversion <<

Seconds since epoch are computed relative to the local time be means of the localtime() function call.

The localtime() function converts the calendar time timep to broken-down time representation, expressed relative to the user's specified timezone.
The function acts as if it called tzset(3) and sets the external variables tzname with information about the current timezone, timezone with the difference between Coordinated Universal Time (UTC) and local standard time in seconds, and daylight to a nonzero value if daylight savings time rules apply during some part of the year.


Backwards coversion adheres to the same rule, of course, else you would get different results depending on the direction of the conversion.
0
 

Author Comment

by:Intoweb
ID: 38792279
Thanks, that makes sense, I guess. But the localtime and timezones are the same on all our servers, so that it not our problem.
0
 

Author Comment

by:Intoweb
ID: 38792284
I found it. The problem was caused by the timezone, but it was inside php.ini and not the server time itself. Thanks.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38794140
That's kind of what I was expecting.  One of the oddities about using timezones in PHP is that if you want just the date in a timezone that has "Daylight Savings Time", you need to ask what day it is at noon and not midnight.  The DST calculations around midnight will drive you crazy wondering what is going on, especially on the day it changes.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now