MySQL 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 Diagram: 1
Syntax Diagram: 2
MySQL Version: 8.0
The following statement will return the current UTC date.
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.
mysql> SELECT UTC_DATE()+0; +--------------+ | UTC_DATE()+0 | +--------------+ | 20150414 | +--------------+ 1 row in set (0.04 sec)
All Date and Time Functions:
Click here to see the MySQL Date and time functions.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join