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

This is really weird for me.

I tried: <?php echo strtotime(date("Ymd H:i:s")); ?> <?php echo strtotime(date("Ymd H:i:s")); ?>

He's back: 1351498120 .

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

he returned the same result: 1351498120 .

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

It returns: 1351533600 .

If I run this query: SELECT UNIX_TIMESTAMP('2012-10-29 18:00:00') ,

he returns: 1351513800

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

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

+4
source share
2 answers

There is a difference of 5.5 hours between 2, which indicates that this is a problem with the time zone on both ends. MySql Server time zone can be configured in different ways.

 SET time_zone = timezonename; 

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

+7
source
+1
source

Source: https://habr.com/ru/post/1442690/


All Articles