w3resource

MySQL UTC_TIMESTAMP() function

UTC_TIMESTAMP() function

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.

Note: Since UTC_TIMESTAMP() works on current datetime, your output may vary from the output shown.

This function is useful in -

  • UTC_TIMESTAMP() is not affected by local time zones, making it useful for scenarios where consistent time measurement is required across different locations.
  • It's useful for filtering records or data based on date and time criteria, such as selecting records within a specific date and time range.
  • UTC_TIMESTAMP() is valuable in log tables to record when events or actions occurred, providing an audit trail for system activity with standardized date and time information.
  • The UTC timestamp format is commonly used for exchanging date and time-related information between different systems or applications, ensuring consistency in timestamp representation.
  • Since UTC doesn't observe Daylight Saving Time, using UTC_TIMESTAMP() helps avoid potential complications caused by changes in local time zone offsets.
  • In real-time applications where precise date and time measurements are crucial, UTC_TIMESTAMP() ensures that the timestamp is represented in a standardized format.
  • As it provides a timestamp in UTC, it allows for consistent and accurate timestamp comparisons regardless of the time zone settings of the server.

Syntax:

UTC_TIMESTAMP; UTC_TIMESTAMP()

Syntax Diagram: 1

MySQL UTC_TIMESTAMP() Function - Syntax Diagram

Syntax Diagram: 2

MySQL UTC_TIMESTAMP() Function - Syntax Diagram

MySQL Version: 8.0


Pictorial Presentation:

Pictorial Presentation of MySQL UTC_TIMESTAMP() function

Example: MySQL UTC_TIMESTAMP() function

The following statement will return the current UTC date and time.

Code:

SELECT UTC_TIMESTAMP,UTC_TIMESTAMP();

Output:

mysql> SELECT UTC_TIMESTAMP,UTC_TIMESTAMP();
+---------------------+---------------------+
| UTC_TIMESTAMP       | UTC_TIMESTAMP()     |
+---------------------+---------------------+
| 2015-04-14 22:52:11 | 2015-04-14 22:52:11 | 
+---------------------+---------------------+
1 row in set (0.01 sec)

Example: UTC_TIMESTAMP() function in numeric format

The following statement will return the current UTC date and time in numeric format.

Code:

SELECT UTC_TIMESTAMP()+0;

Output:

mysql> SELECT UTC_TIMESTAMP()+0;
+-----------------------+
| UTC_TIMESTAMP()+0     |
+-----------------------+
| 20150414225635.000000 | 
+-----------------------+
1 row in set (0.00 sec)

Video Presentation:

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: UTC_TIME()
Next: WEEK()



Follow us on Facebook and Twitter for latest update.