Collections:
CONVERT_TZ() - Converting Time Zone
How to convert a time in one timezone to another timezone using the CONVERT_TZ() function?
✍: FYIcenter.com
CONVERT_TZ(dt, from_tz, to_tz) is a MySQL built-in function that
converts a time in one timezone to another timezone.
For example:
SELECT CONVERT_TZ('2023-01-01 12:00:00','+00:00','+10:00');
-- +-----------------------------------------------------+
-- | CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00') |
-- +-----------------------------------------------------+
-- | 2023-01-01 22:00:00 |
-- +-----------------------------------------------------+
SELECT CONVERT_TZ('2023-01-01 12:00:00', 'GMT', 'MET');
-- +-------------------------------------------------+
-- | CONVERT_TZ('2023-01-01 12:00:00', 'GMT', 'MET') |
-- +-------------------------------------------------+
-- | '2023-01-01 13:00:00' |
-- +-------------------------------------------------+
SELECT CONVERT_TZ('2023-01-01 12:00:00', 'GMT', 'MET');
-- +-------------------------------------------------+
-- | CONVERT_TZ('2023-01-01 12:00:00', 'GMT', 'MET') |
-- +-------------------------------------------------+
-- | '2023-01-01 13:00:00' |
-- +-------------------------------------------------+
SELECT CONVERT_TZ('2030-08-25 00:00:00', 'Australia/Brisbane', 'Australia/Perth');
-- +----------------------------------------------------------------------------+
-- | CONVERT_TZ('2030-08-25 00:00:00', 'Australia/Brisbane', 'Australia/Perth') |
-- +----------------------------------------------------------------------------+
-- | '2030-08-24 22:00:00' |
-- +----------------------------------------------------------------------------+
Reference information of the CONVERT_TZ() function:
CONVERT_TZ(dt, from_tz, to_tz): modtime Converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. Time zones can be specified specified in ISO format. Time zones can be specified specified in short or long names, if the timezone package is installed, see https://dev.mysql.com/downloads/timezones.html Arguments, return value and availability: dt: Required. The datetime to be converted. from_tz: Required. The timezone to be converted from. to_tz: Required. The timezone to be converted to. modtime: Return value. The updated datetime. Available since MySQL 5.7.
2023-11-17, 922🔥, 0💬
Popular Posts:
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...
How To Connect to a MySQL Server with a Port Number in MySQL? If you want to connect a MySQL server ...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To Convert a Unicode Strings to Non-Unicode Strings in SQL Server Transact-SQL? Since Unicode ch...
How To Locate and Take Substrings with CHARINDEX() and SUBSTRING() Functions in SQL Server Transact-...