O
O
Optimus2017-07-22 23:13:46
MySQL
Optimus, 2017-07-22 23:13:46

How to store the time zone selected by the user?

1) What is the best way to store the time correction for this user in the database?
The meaning of the question is that if a person chooses for himself in the MSC + 7 settings, then you need to not only display his time, but correctly display that his store is no longer working, or stop visitors from ordering delivery for "today" because today is already over and he already needs to show the "tomorrow's" date on his site.
2) To store the date of the order in the database in the same form for everyone?
Those. if the order arrives at 21:00 Moscow time and the user has the time Moscow time in the settings, then we write the date 25 in the database, the same order is at 21:00 Moscow time but the user has MSK + 7 in the settings, then we write the number in the database order 26th?
3) Should I use TIMESTAMP in this case?
A user from Vladik and his store must be closed 7 hours earlier than in Moscow time. But the timestamp writes to the NOW() database, and even taking into account the set MySQL time zone, and it is the same, and not different for all users. Unless manually when writing to the database, then add timestamp + 7 * 3600 to get the true time of the order for the user from Vladik.
All of the above implies that the user's store is used by users from the same region as himself, i.e. Muscovites will not go to the site for Vladik and will not be surprised that tomorrow's date is already there.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2017-07-23
@ThunderCat

php.net/manual/en/function.date-default-timezone-s...

K
kpa6uu, 2017-07-23
@kpa6uu

It is better to store the user's time zone in the format a la Europe / Moscow (this will avoid problems with the transition to daylight saving time).
You can also store it as an offset from UTC, but this brings up the previously discussed daylight savings time problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question