The UTC_TIMESTAMP SQL Function in MySQL and MariaDB - UTC timestamp
UTC_TIMESTAMP
Syntax:
UTC_TIMESTAMP([Precision])
Return value:
DATETIME
Function type:
Date and Time function
Function Description
The UTC_TIMESTAMP() function returns the current UTC date and time as a string YYYY-MM-DD hh:mm:ss or numerically as BIGINTYYYYMMDDhhmmss or as DECIMALYYYYMMDDhhmmss.microseconds, depending on whether the function is used in string or numeric context.
The value is expressed in the format of the current session time zone.
The "Precision" argument can be specified to indicate a fractional second precision from 0 to 6 digits.
The specification of "Precision" must be a written number from 0-6. Expressions or variables produce a syntax error, larger values produce a precision error.
With the UTC_TIMESTAMP() function, the parentheses can be omitted if "Precision" is not specified.
Setting the system variable timestamp affects the UTC_TIMESTAMP() function.
errno: 1426 sqlstate: 42000 error: Too big precision 7 specified for 'utc_timestamp'. Maximum is 6
selectutc_timestamp(3 + 2)
errno: 1064 sqlstate: 42000 error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '+ 2)' at line 1
selectutc_timestamp(@a)
errno: 1064 sqlstate: 42000 error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@a)' at line 1
The examples were created with the MyWAY SQL manager: Download
How to use the UTC_TIMESTAMP() function in MySQL and MariaDB databases
In MySQL and MariaDB, the UTC_TIMESTAMP() function returns the current UTC date and the current UTC time (Coordinated Universal Time) as a datetime value in the format "YYYY-MM-DD HH:MM:SS". The function always returns the current UTC date and time, regardless of the time zone setting on the server or the client. This allows consistent and standardized work with "date and time" values across different time zones, used in different SQL statements to retrieve the UTC date and time from tables or to set values. Calculations can be performed using other functions and SQL operations, or the obtained UTC timestamp can be manipulated.