I'm migrating old users table to the new database and in the old table, user timezone saved in the format like 4
, 4.5
or -4
, -4.5
which means UTC+04:00
, UTC+04:30
and UTC-04:00
, UTC-04:30
. I want somehow convert it to the format I can later easily use by PHP to convert all dates to user timezone. I found method timezone_name_from_abbr()
which is working for integers like this timezone_name_from_abbr('', -4 * 3600, 0)
= America/Halifax"
, but how to be with doubles, timezone_name_from_abbr
expecting only integers? Also even with integers, it's now clear should I use DST or not when migrating concrete user. Any idea how I can determine timezone by hours offset?
Asked
Active
Viewed 54 times
0

Funk Forty Niner
- 74,450
- 15
- 68
- 141

Bogdan Dubyk
- 4,756
- 7
- 30
- 67
-
I can canvert double value to time zone using for exampe `timezone_name_from_abbr('', (int)(-4.5 * 3600), 0)` but there is values like `8.75` and `timezone_name_from_abbr` can't recognize such timezone – Bogdan Dubyk Jan 01 '20 at 04:35
-
umm, I do not see how it can help me so far. I do not need to save a date or time, I want to save user timezone in the format I can later easily use by PHP or other languages to convert any DateTime to that timezone, ideally is to format like this `America/New_York`. You can point me out to the function I can use to convert for example 8.75 to `Australia/Eucla` b-z I do not see such function so fat. Thanks! – Bogdan Dubyk Jan 01 '20 at 05:04
-
Basically, this cannot be done. You need additional information, such as the user's location. – Matt Johnson-Pint Jan 01 '20 at 21:33
-
Okay, thanks. There is also latitude/longitude, It should be possible to get time zone by that – Bogdan Dubyk Jan 01 '20 at 21:48
-
Yep! See https://stackoverflow.com/questions/16086962/how-to-get-a-time-zone-from-a-location-using-latitude-and-longitude-coordinates. In particular, try https://github.com/minube/geo-timezone – Matt Johnson-Pint Jan 02 '20 at 04:44