TO_DAYS
Description
A date calculation function that converts a date to a numeric value representing days, calculating the total number of days from December 31, year 1 (the reference date) to the specified date.
This function behaves consistently with the to_days function in MySQL.
Syntax
TO_DAYS(`<date_or_date_expr>`)
Parameters
Parameter | Description |
---|---|
<date_or_time_expr> | Input datetime value, supports date/datetime types. For datetime and date formats, please refer to datetime conversion and date conversion |
Return Value
Returns BIGINT type representing the number of days.
Examples
--input date type
select to_days('2007-10-07');
+---------------------------------------+
| to_days('2007-10-07') |
+---------------------------------------+
| 733321 |
+---------------------------------------+
--input datetime type
select to_days('2007-10-07 10:03:09');
+------------------------------------------------+
| to_days('2007-10-07 10:03:09') |
+------------------------------------------------+
| 733321 |
+------------------------------------------------+