Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Column specific time zone during insert

Tags:

timezone

mysql

Let's say I have 2 TIMESTAMP fields/columns, event and stamp. For event field, when we insert, I want to set time zone so that event will use user specified time zone. However, I don't want stamp to use that time zone. I want stamp to use whatever default time zone the server is using.

SET time_zone = <UTC offset>;

does not work since it will affect both event and stamp where we only want event to be affected by the time zone.

Is there a way to set time zone for specific columns during insert?

like image 392
developarvin Avatar asked Dec 05 '25 05:12

developarvin


1 Answers

MySQL doesn't bother about timezones when you insert a date.

I would recommend storing the date/time in GMT (+00:00) and have another field that stores the timezone used (e.g. "Europe/Amsterdam").

Edit

I'm not entirely sure you would need the used timezone though, since you can format a GMT time in any way you'd like inside your scripts / apps.

like image 180
Ja͢ck Avatar answered Dec 07 '25 20:12

Ja͢ck