Anyone knows if there is such a function in MySQL?
UPDATE
This doesn't output any valid info:
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+
Or maybe MySQL itself can't know exactly the time_zone
used,that's fine, we can involve PHP
here, as long as I can get valid info not like SYSTEM
...
The command mention in the description returns "SYSTEM" which indicated it takes the timezone of the server. Which is not useful for our query.
Following query will help to understand the timezone
Above query will give you the time interval with respect to Coordinated Universal Time(UTC). So you can easily analyze the timezone. if the database time zone is IST the output will be 5:30
UTC_TIMESTAMP
In MySQL, the UTC_TIMESTAMP returns the current UTC date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format depending on the usage of the function i.e. in a string or numeric context.
NOW()
NOW() function. MySQL NOW() returns the value of current date and time in 'YYYY-MM-DD HH:MM:SS' format or YYYYMMDDHHMMSS.uuuuuu format depending on the context (numeric or string) of the function. CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), LOCALTIME, LOCALTIME(), LOCALTIMESTAMP, LOCALTIMESTAMP() are synonyms of NOW().
The query below returns the timezone of the current session.
As Jakub Vrána (The creator or Adminer and NotORM) mentions in the comments, to select the current timezone offset in
TIME
use:It will return:
02:00:00
if your timezone is +2:00 for that dateI made a cheatsheet here: Should MySQL have its timezone set to UTC?
My PHP framework uses
on after connect, where 'Whatever' == date_default_timezone_get()
Not my solution, but this ensures
SYSTEM
timezone of MySQL server is always the same as PHP's oneSo, yes, PHP is strongly envolved and can affect it
To get the current time according to your timezone, you can use the following (in my case its '+5:30')
You just need to restart mysqld after altering timezone of System..
The Global time zone of MySQL takes timezone of System. When you change any such attribute of system, you just need a restart of Mysqld.