shasi kanth
shasi kanth

Reputation: 7094

Why the php timestamp is different from mysql UNIX_TIMESTAMP for a future date?

This is really strange for me.

I tried: <?php echo strtotime(date("Y-m-d H:i:s")); ?>

It returned: 1351498120.

Also, when i ran this query: SELECT UNIX_TIMESTAMP(now()) ,

it returned the same result: 1351498120.

But when i tried: <?php echo strtotime(date("2012-10-29 18:00:00")); ?>

It returns: 1351533600.

Whereas, if i run this query: SELECT UNIX_TIMESTAMP('2012-10-29 18:00:00'),

it returns: 1351513800

Now my question is: why the timestamps of php and mysql are same for current date, but different for future dates? Is there a way to compare them for future dates?

(NOTE: I have UTC as default timezone in php)

Upvotes: 5

Views: 1542

Answers (2)

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46728

There is a 5.5 hour difference between the 2, which indicates it is a timezone issue, on either end. The MySql Server's Timezone could be configured differently.

SET time_zone = timezonename;

can be used to set timezone for the current session. Check MySQL Date and Time Functions

Upvotes: 8

Jian
Jian

Reputation: 70

Try to set the default time zone

http://php.net/manual/en/function.date-default-timezone-set.php

Upvotes: 2

Related Questions