MariaDB CONVERT_TZ() Function
In MariaDB, CONVERT_TZ() is a built-in function used to convert a datetime value from one time zone to another.
MariaDB CONVERT_TZ() Syntax
This is the syntax of the MariaDB CONVERT_TZ() function:
CONVERT_TZ(datetime, fromTimeZone, toTimeZone)
Parameters
datetime-
Required. The datetime to process.
fromTimeZone-
Required. The current time zone.
toTimeZone-
Required. The new time zone.
fromTimeZone and toTimeZone supports the following formats:
- Using
SYSTEMmeans the same time zone as the current system. - Use
+/-[H]H:MMmeans offset from UTC time, such as'+10:00','-6:00','+05:30'etc. - Use the name of the time zone, for example:
'Europe/Helsinki','US/Eastern','MET','GMT'.
If you provide no parameters or the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CONVERT_TZ'.
Return value
The MariaDB CONVERT_TZ() function returns a datetime in the new timezone.
The CONVERT_TZ() function will return NULL if the argument is error or NULL.
MariaDB CONVERT_TZ() Examples
This statement shows the basic usage of the MariaDB CONVERT_TZ() function:
SELECT
CONVERT_TZ('2023-01-06 12:00:00', '+00:00', '+01:00'),
CONVERT_TZ('2023-01-06 12:00:00', '+00:00', '-01:00'),
CONVERT_TZ('2023-01-06 12:00:00', '+00:00', '-03:00')\G
Output:
CONVERT_TZ('2023-01-06 12:00:00', '+00:00', '+01:00'): 2023-01-06 13:00:00
CONVERT_TZ('2023-01-06 12:00:00', '+00:00', '-01:00'): 2023-01-06 11:00:00
CONVERT_TZ('2023-01-06 12:00:00', '+00:00', '-03:00'): 2023-01-06 09:00:00If you want to use named timezones, please set up named timezones in MariaDB first.
Conclusion
In MariaDB, CONVERT_TZ() is a built-in function used to convert a datetime value from one time zone to another.