echo strtotime('2010-09-11 12:15:01');

Returns: 1284207301

SELECT UNIX_TIMESTAMP('2010-09-11 12:15:01')

Returns: 1284200101

Why the difference?

share|improve this question

4 Answers

up vote 2 down vote accepted

This is commonly caused by setting PHP and MySQL to use different timezones, as well as discrepancies in the system time if they happen to be located in different servers.

UNIX timestamps are the number of seconds that have passed since the UNIX epoch on midnight January 1, 1970 UTC so timezone differences will give different timestamps.

share|improve this answer
Both PHP and MySQL are on my local development server which has GMT+1 time. – Richard Knop Sep 11 '10 at 13:09
2  
@Richard yes, but PHP and mySQL probably have different time zone settings – Pekka 웃 Sep 11 '10 at 13:12
1  
Yandros' answer may help. – BoltClock Sep 11 '10 at 13:12

The answer is in the php.net article about strtotime:

This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 there are easier ways to define the timezone that is used across all date/time functions. That process is explained in the date_default_timezone_get() function page.

Short version: strtotime uses your timezone by default, UNIX_TIMESTAMP does not.

share|improve this answer

1284207301-1284200101 = 7200 -> 2 hours. Such a perfectly rounded difference isn't due to a bug, it's a timezone diference. Most likely one's in UTC/GMT, and the other's UTC +/- 2

share|improve this answer

My guess is that Unix time is GMT and the other is your local timezone, there is exactly 2 hours difference (7200/60/60) between the 2 outputs

share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.