Reputation: 7094
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
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
Reputation: 70
Try to set the default time zone
http://php.net/manual/en/function.date-default-timezone-set.php
Upvotes: 2