UTC_DATE Examples – MySQL

In MySQL, you can use the UTC_DATE function to return the UTC date. UTC stands for Coordinated Universal Time and it’s the primary time standard by which the world regulates clocks and time.

The result is returned either in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in a string or numeric context.

Syntax

You can use either of the following two forms:

UTC_DATE
UTC_DATE()

So no arguments are required.

Example 1 – Basic Usage

Here’s an example to demonstrate.

SELECT UTC_DATE;

Result:

+------------+
| UTC_DATE   |
+------------+
| 2018-07-05 |
+------------+

Example 2 – With Parentheses

In this example I add the parentheses (of course, this makes no difference to the outcome).

SELECT UTC_DATE();

Result:

+------------+
| UTC_DATE() |
+------------+
| 2018-07-05 |
+------------+

Example 3 – Numerical Context

The previous examples were all returned in ‘YYYY-MM-DD’ format. This is because they were used in a string context.

In this example I use the function in a numerical context. I do this by adding a number to the function.

SELECT UTC_DATE() + 0;

Result:

+----------------+
| UTC_DATE() + 0 |
+----------------+
|       20180705 |
+----------------+

In this case I added zero, which kept the date the same. However, the result is now in YYYYMMDD format.

There’s nothing to stop you from adding another number. Example:

SELECT UTC_DATE() + 5;

Result:

+----------------+
| UTC_DATE() + 5 |
+----------------+
|       20180710 |
+----------------+

Also see UTC_TIME Examples for returning the UTC time.