HelloPablo
HelloPablo

Reputation: 625

Mysql: Set time_zone for select queries, UTC for everything else

Is it possible to configure MySQL (at runtime) to use UTC for all write queries, but another timezone for all SELECT queries?

I'm storing all dates in UTC (additionally, the app will always pass UTC datetimes to MySQL) and have MySQL configured to be running in UTC (using SET time_zone = '+0:00'); but is there a way for it to automatically translate all SELECT into another timezone?

I realise I can do this in code, but if I can make MySQL do the job for me that'd be much easier.

To be clear: I'd also like to just run a command once, not use any of the date/time formatting functions for each query.

Upvotes: 2

Views: 4046

Answers (1)

Sundar
Sundar

Reputation: 4650

User CONVERT_TZ() in mysql function

SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');

Ref : http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz

Upvotes: 1

Related Questions