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)
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
Try to set the default time zone
http://php.net/manual/en/function.date-default-timezone-set.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With