2

Consider this. On my server, I convert a (UTC/GMT) timestring like this:

strtotime('Fri Feb 18 21:08:38 +0000 2011')

My server returns

1298063318

This is correct, since all unix timestamp converters that I tested, return the same. And vice versa, if I insert not the date but the timestamp, I get returned the timestring as given above. But if I convert the timestamp on my server:

date("Y-m-d H:i:s", 1298063318); 

I get back a different date than expected (being 'Fri Feb 18 21:08:38 +0000 2011'):

2011-02-18 22:08:38

So it's off an hour. This is probably because my servers timezone is set at Europe/Paris, and it thus translates the timestamp into UTC/GTM + 1. But MySQL, ran on the same server and having the same timezone, gives me back another result:

SELECT FROM_UNIXTIME(1298063318) = 2011-02-18 22:08:15

In other words, it is off 18 seconds. Can somebody explain why?

1 Answer 1

4

For MySQL, a leap second correction is used for the date functions (MySQL Documentation). For PHP date functions, leap seconds are not taken into account. For that reason, you get now a 24 seconds difference.

You can try the following to solve your problem: http://pumka.net/2010/10/24/why-mysql-timestamp-is-24-seconds-different-from-php/

PS. 38 - 15 = 23

Sign up to request clarification or add additional context in comments.

1 Comment

Would upvote twice if possible, just for the PS xD How did I miscalculate?! Must be the heavy breakfast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.