Summary: in this tutorial, you will learn how to use the MySQL UTC_DATE() function to get the current UTC date.
Introduction to the MySQL UTC_DATE() function
The UTC_DATE() function lets you get the current date in Coordinated Universal Time (UTC).
Here’s the syntax of the UTC_DATE() function:
UTC_DATE()Code language: SQL (Structured Query Language) (sql)The UTC_DATE() doesn’t accept any argument and returns the current date in UTC. The UTC() function is useful when you want to handle dates consistently across different time zones.
MySQL UTC_DATE() function examples
Let’s take some examples of using the UTC_DATE() function.
1) Simple UTC_DATE() function example
The following example uses the UTC_DATE() function to display the current UTC DATE():
SELECT UTC_DATE();Code language: SQL (Structured Query Language) (sql)Output:
+------------+
| UTC_DATE() |
+------------+
| 2023-10-18 |
+------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)2) Using the UTC_DATE() function with table data
First, create a new table called events with the following structure:
CREATE TABLE events (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
date DATE NOT NULL
);Code language: SQL (Structured Query Language) (sql)Second, insert some rows using the UTC_DATE() function:
INSERT INTO events (name, date)
VALUES ('AI Conference', UTC_DATE()),
('Tech Summit', UTC_DATE()),
('RPA Conf', UTC_DATE());Code language: SQL (Structured Query Language) (sql)Third, query data from the events table:
SELECT
name,
date
FROM
events;Code language: SQL (Structured Query Language) (sql)Output:
+---------------+------------+
| name | date |
+---------------+------------+
| AI Conference | 2023-10-18 |
| Tech Summit | 2023-10-18 |
| RPA Conf | 2023-10-18 |
+---------------+------------+
3 rows in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)Summary
- Use the
UTC_DATE()function to get the current UTC date.