Reputation: 83755
echo strtotime('2010-09-11 12:15:01');
Returns: 1284207301
SELECT UNIX_TIMESTAMP('2010-09-11 12:15:01')
Returns: 1284200101
Why the difference?
Upvotes: 0
Views: 2306
Reputation: 135171
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
Upvotes: 1
Reputation: 360872
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
Upvotes: 1
Reputation: 732
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.
Upvotes: 3
Reputation: 724452
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.
Upvotes: 2