Answer the question
In order to leave comments, you need to log in
Displaying the creation time of a record in the database depending on the user's time zone?
Good day!
Interested in the following question.
There is a table in the database for storing blog posts. It has a field of type datetime , which stores the time the post was created in the following format: 2016-02-12 18:50:51 . By default, the site is set to Europe/Moscow time zone . Also, each user in the profile settings can choose their own time zone.
Is it possible to somehow display a list of posts whose creation time will correspond to the user's time zone?
Thanks in advance for your reply!
Answer the question
In order to leave comments, you need to log in
Maybe something like this:
$ts = strtotime('2016-02-12 18:50:51'.' MSK');
$tz = new DateTimeZone('Pacific/Nauru');
$date = new DateTime("@".$ts);
$date->setTimeZone($tz);
echo($date->format('Y-m-d H:m:s'));
Mysql timestamp saves and stores in UTC, but the output is done from the system settings
By default, the system always goes -> config -> query
I think it will be correct to set the hourly search from the script for php then mysql
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question