E
E
Evgeny Ivanov2018-03-16 12:21:19
PHP
Evgeny Ivanov, 2018-03-16 12:21:19

How to fix time shift (MySQL query)?

The difference between local time (Open Server) and time on the server (VPS) is 3 hours. (on the server 3 hours less)
On the VPS server - do not change the time. But some of the settings are probably possible.
The server has a database with a table - table. The table has 2 columns - time and data.
time - unix timestamp. $time=time();data is just a number.
I was told that records for the current day, the previous day (any number of days ago) - exactly from 00.00 to 24.00 can be displayed like this.

$result=mysql_query("SELECT `time`,`data` FROM `table` where `time`>UNIX_TIMESTAMP(SUBDATE(CURDATE(),1)) AND `time`<UNIX_TIMESTAMP(SUBDATE(CURDATE(),2))") or die (mysql_error());

And it works.
Since I am developing a project on Open Server, I downloaded the database from the VPS server.
I use (in the project code) a request - everything is fine, but the time is less than 3 hours. And it is clear DB from the server.
I wrote the code - added 10800 seconds to the time and everything became as it should. Works on Open Server.
My time is local.
Next
I uploaded the project to the VPS server.
I use (in the project code) a query - and I see: the time is local, but the selection is shifted by 3 hours.
But on Open Server, this is not the case. Everything is clear from 00.00 to 24.00.
How can this be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2018-03-16
@logpol32

when initializing the connection, execute the query "SET time_zone = '+2:00';" (or other appropriate time zone), in PHP, respectively, also set the time zone so that there is no discrepancy, there is no need to touch the OS settings.

A
Alexander null, 2018-03-16
@snikes


Change the default-time-zone in the mysql config
with a shift in the right direction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question