w3resource

MySQL UTC_DATE() function

UTC_DATE() function

MySQL UTC_DATE returns the current UTC (Coordinated Universal Time) date as a value in 'YYYY-MM-DD' or YYYYMMDD format depending on the context of the function i.e. in a string or numeric context.

This function is useful in -

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

Syntax:

UTC_DATE; UTC_DATE()

Syntax Diagram: 1

MySQL UTC_DATE() Function - Syntax Diagram

Syntax Diagram: 2

MySQL UTC_DATE() Function - Syntax Diagram

MySQL Version: 8.0


Pictorial Presentation:

Pictorial Presentation of MySQL UTC_DATE() function

Example:

The following statement will return the current UTC date.

Code:

SELECT UTC_DATE,UTC_DATE();

Output:

mysql> SELECT UTC_DATE,UTC_DATE();
+------------+------------+
| UTC_DATE   | UTC_DATE() |
+------------+------------+
| 2015-04-14 | 2015-04-14 | 
+------------+------------+
1 row in set (0.00 sec)

Example : UTC_DATE() function in numeric format

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

Code:

SELECT UTC_DATE()+0;

Output:

mysql> SELECT UTC_DATE()+0;
+--------------+
| UTC_DATE()+0 |
+--------------+
|     20150414 | 
+--------------+
1 row in set (0.04 sec)

Video Presentation:

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: UNIX_TIMESTAMP()
Next: UTC_TIME()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mysql/date-and-time-functions/mysql-utc_date-function.php