©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The CONVERT_TZ SQL Function in MySQL and MariaDB - Convert between time zones

CONVERT_TZSyntax:CONVERT_TZ(Date, From time zone, To time zone)
Return value:DATETIME
Function type:Date and Time function
Function Description

The CONVERT_TZ() function converts a DATETIME value "Date" "From time zone" "To time zone".

To use named time zones like GMT, MET or America/New_York ... the time_zone tables loaded.

No conversion takes place if the value of the "From time zone" argument in the conversion is outside the supported TIMESTAMP range: 1970-01-01 00:00:01 to 2038-01-19 05:14:07 UTC.

The CONVERT_TZ() function returns NULL if any of the arguments are invalid or NULL.

SQL Examples for the CONVERT_TZ function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

select now(), convert_tz(now(), '+00:00','+01:00');
select now(), convert_tz(now(), '+01:00','+00:00');

select now(), utc_timestamp(), convert_tz(now(), '+00:00','-02:00');

select convert_tz(now(), '','+01:00');
select convert_tz(null'+00:00','+01:00');
select convert_tz(now(), null,'+01:00');
select convert_tz(now(), '+00:00',null);

now()
convert_tz(now(), '+00:00','+01:00')
datetime(19)datetime(19)
31.03.2023 11:21:5531.03.2023 12:21:55
now()
convert_tz(now(), '+01:00','+00:00')
datetime(19)datetime(19)
31.03.2023 11:21:5531.03.2023 10:21:55
now()
utc_timestamp()
convert_tz(now(), '+00:00','-02:00')
datetime(19)datetime(19)datetime(19)
31.03.2023 11:21:5531.03.2023 09:21:5531.03.2023 09:21:55
convert_tz(now(), '','+01:00')
datetime(19)
NULL
convert_tz(null, '+00:00','+01:00')
datetime(19)
NULL
convert_tz(now(), null,'+01:00')
datetime(19)
NULL
convert_tz(now(), '+00:00',null)
datetime(19)
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the CONVERT_TZ() function in MySQL and MariaDB databases

In MySQL and MariaDB, the CONVERT_TZ() function is used to convert a date and time value from a time zone to another. This allows date and time values ​​to be adjusted to different time zones based on the provided time zone offsets or names. It is important to note that the CONVERT_TZ() function is based on the time zone information stored in the MySQL or MariaDB time zone tables. These tables contain a mapping between time zone names and their corresponding offsets. It should be ensured that the time zone tables are completed and up to date to ensure accurate conversions.

The CONVERT_TZ() function is particularly useful when working with date and time values ​​in different time zones, for example when converting between UTC and local time zones or when converting between different time zones for international applications.
CONNECTION_IDCONVCONVERTCONVERT_TZCOSCOTCOUNT

Further MySQL und MariaDB SQL Date and Time functions

ADDDATEADDDATE(Date, [INTERVAL] Number [Unit])
More about ADDDATE Function

ADDTIMEADDTIME(Date, Expression)
More about ADDTIME Function

CURDATECURDATE()
More about CURDATE Function

CURTIMECURTIME([Precision])
More about CURTIME Function

CURRENT_DATECURRENT_DATE(-)
More about CURRENT_DATE Function

CURRENT_TIMECURRENT_TIME([Precision])
More about CURRENT_TIME Function

CURRENT_TIMESTAMPCURRENT_TIMESTAMP([Precision])
More about CURRENT_TIMESTAMP Function

DATEDATE(Date and Time)
More about DATE Function

DATE_ADDDATE_ADD(Date, INTERVAL Number Unit)
More about DATE_ADD Function

DATE_SUBDATE_SUB(Date, INTERVAL Number Unit)
More about DATE_SUB Function

FROM_DAYSFROM_DAYS(Number of days)
More about FROM_DAYS Function

FROM_UNIXTIMEFROM_UNIXTIME(Unix timestamp [, Format])
More about FROM_UNIXTIME Function

LOCALTIMELOCALTIME([Precision])
More about LOCALTIME Function

LOCALTIMESTAMPLOCALTIMESTAMP([Precision])
More about LOCALTIMESTAMP Function

MAKEDATEMAKEDATE(Year, Day of year)
More about MAKEDATE Function

MAKETIMEMAKETIME(Hours, Minutes, Seconds)
More about MAKETIME Function

NOWNOW([Precision])
More about NOW Function

SEC_TO_TIMESEC_TO_TIME(Seconds)
More about SEC_TO_TIME Function

SLEEPSLEEP(Seconds)
More about SLEEP Function

STR_TO_DATESTR_TO_DATE(String, Format)
More about STR_TO_DATE Function

SUBDATESUBDATE(Date, [INTERVAL] Number [Unit])
More about SUBDATE Function

SUBTIMESUBTIME(Date and Time, Deduction)
More about SUBTIME Function

SYSDATESYSDATE()
More about SYSDATE Function

TIMETIME(Date and Time)
More about TIME Function

TIMEDIFFTIMEDIFF(Date 1, Date 2)
More about TIMEDIFF Function

TIMESTAMPTIMESTAMP(Date [, Addition])
More about TIMESTAMP Function

TIMESTAMPADDTIMESTAMPADD(Unit, Number, Date)
More about TIMESTAMPADD Function

TIMESTAMPDIFFTIMESTAMPDIFF(Unit, Date 1, Date 2)
More about TIMESTAMPDIFF Function

UTC_DATEUTC_DATE()
More about UTC_DATE Function

UTC_TIMEUTC_TIME([Precision])
More about UTC_TIME Function

UTC_TIMESTAMPUTC_TIMESTAMP([Precision])
More about UTC_TIMESTAMP Function

DAYDAY(Date)
More about DAY Function

DAYOFMONTHDAYOFMONTH(Date)
More about DAYOFMONTH Function

DAYOFWEEKDAYOFWEEK(Date)
More about DAYOFWEEK Function

DAYOFYEARDAYOFYEAR(Date)
More about DAYOFYEAR Function

EXTRACTEXTRACT(Unit FROM Date)
More about EXTRACT Function

HOURHOUR(Date and Time)
More about HOUR Function

MICROSECONDMICROSECOND(Date and Time)
More about MICROSECOND Function

MINUTEMINUTE(Date and Time)
More about MINUTE Function

MONTHMONTH(Date)
More about MONTH Function

QUARTERQUARTER(Date)
More about QUARTER Function

SECONDSECOND(Date and Time)
More about SECOND Function

TIME_TO_SECTIME_TO_SEC(Time)
More about TIME_TO_SEC Function

TO_DAYSTO_DAYS(Date)
More about TO_DAYS Function

TO_SECONDSTO_SECONDS(Date and Time)
More about TO_SECONDS Function

UNIX_TIMESTAMPUNIX_TIMESTAMP([Date and Time])
More about UNIX_TIMESTAMP Function

WEEKWEEK(Date [, Mode])
More about WEEK Function

WEEKDAYWEEKDAY(Date)
More about WEEKDAY Function

WEEKOFYEARWEEKOFYEAR(Date)
More about WEEKOFYEAR Function

YEARYEAR(Date)
More about YEAR Function

YEARWEEKYEARWEEK(Date [, Mode])
More about YEARWEEK Function

DAYNAMEDAYNAME(Date)
More about DAYNAME Function

DATE_FORMATDATE_FORMAT(Date and Time, Format)
More about DATE_FORMAT Function

GET_FORMATGET_FORMAT(Type, Format)
More about GET_FORMAT Function

MONTHNAMEMONTHNAME(Date)
More about MONTHNAME Function

TIME_FORMATTIME_FORMAT(Time, Format)
More about TIME_FORMAT Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the CONVERT_TZ SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer