MySQL TO_DAYS() Function
In MySQL, the TO_DAYS()
function converts the specified date to the number of days since year 0 and returns the result.
The TO_DAYS()
function is the opposite of the FROM_DAYS()
function.
TO_DAYS()
Syntax
Here is the syntax of MySQL TO_DAYS()
function:
TO_DAYS(date)
Parameters
date
- Required. a date value.
Return value
The MySQL TO_DAYS()
function returns the number of days from year 0 for the specified date.
If the argument is NULL
, the TO_DAYS()
function will return NULL
.
TO_DAYS()
Examples
Here are some examples of the TO_DAYS()
function.
SELECT
TO_DAYS('2022-02-28'),
TO_DAYS('2022-03-01');
+-----------------------+-----------------------+
| TO_DAYS('2022-02-28') | TO_DAYS('2022-03-01') |
+-----------------------+-----------------------+
| 738579 | 738580 |
+-----------------------+-----------------------+
TO_DAYS()
FROM_DAYS()
A function is the opposite of a function.
SELECT
FROM_DAYS(738579),
TO_DAYS(FROM_DAYS(738579));
+-------------------+----------------------------+
| FROM_DAYS(738579) | TO_DAYS(FROM_DAYS(738579)) |
+-------------------+----------------------------+
| 2022-02-28 | 738579 |
+-------------------+----------------------------+