tags:

views:

66

answers:

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

Returns: 1284207301

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

Returns: 1284200101

Why the difference?

+2  A: 

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.

BoltClock
Both PHP and MySQL are on my local development server which has GMT+1 time.
Richard Knop
@Richard yes, but PHP and mySQL probably have different time zone settings
Pekka
Yandros' answer may help.
BoltClock
+2  A: 

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.

Yandros
+1  A: 

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

Marc B
+1  A: 

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

SQLMenace