S
S
Sergey Brovko2018-03-23 10:32:19
Yii
Sergey Brovko, 2018-03-23 10:32:19

How to find out the reason for the discrepancy in time?

Hello, I need your help. There is a project on yii2 (inherited), in fact, it represents an interface for selecting records from the database. There are several sortings like selecting records by date, etc. (widget yii2-kartik-datepicker something there). Date information is stored in the database as unixtime, an integer field.
Actually the reason why I am writing here. It used to work on one server (VPS Ubuntu 16.04, PHP 7.0(.25), MariaDB 5.5, Apache 2.4 i.e. regular LAMP), recently I had to move it all to a new server. VPS CentOS7, PHP 7.0(.28), base and webserver are the same. And then the fun began. For some reason, entries in the table began to be displayed with a difference of +1 hour (although the time stored in unixtime format is correct), if we select entries from the widget for the 20th day, the entries show correctly, but the calendar itself is placed on the 19th. I thought I missed somewhere with time zones, but no:
date on both servers displays the same time and date.
SELECT NOW() in the database displays the same time
echo date('H:i:s'); outputs the same time.
The project files were not changed, they were copied by rsync and the database access parameters were changed in the config. Already rummaged through everything, where is the dog buried?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fedor Grebennikov, 2018-03-24
@cyber01

Most likely such cases: if dates are displayed through Yii::$app->formatter, then it can display the date through ICU.
https://www.yiiframework.com/doc/guide/2.0/en/outp...
It happened to me that the old version of ICU was in the system and there was a mess with winter / summer time, as I understood it. After the update it was ok.
In another case, the update failed, because there was no access to the server, there I rewrote all the dates to "PHP date () syntax", it was displayed correctly

I
Igor Vasiliev, 2018-03-23
@Isolution666

I used to use date(); too. hence the time discrepancy, date(); not suitable for RECORDING date and time. To record the time, I use time() ; - works fine on php7, old version of mktime() ; - there is a risk that errors will come out on the server. Searching for information with this plugin is the best thing, but recording the date and time is better with time();
If you don't know, this is a unix date.
php.net/manual/en/function.time.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question