TO_DAYS
TO_DAYS is a date function in SQL that converts a date or datetime value into a numeric value representing the number of days from the year 0 to the given date. It is often used to perform calculations on date or datetime values.
TO_DAYS(date)
- date: This parameter represents the date for which the number of days up to the date will be returned. It must be a value that can be interpreted as a date such as a ‘YYYY-MM-DD’ or ‘YY-MM-DD’ formatted string, a ‘DD-MM-YYYY’ or ‘DD-MM-YY’ formatted string, a DATE, a DATETIME, or a TIMESTAMP. Incorrectly formatted dates or those outside of the valid range (‘1000-01-01’ to ‘9999-12-31’) return NULL.
Example
SELECT TO_DAYS('2018-06-15');
Output
737226
Explanation
The TO_DAYS()
function in MySQL is used to get the number of days between the given date and zero date (0 AD). In the provided example, TO_DAYS()
function is used to return the number of days between ‘2018-06-15’ and zero date. The output is 737226, indicating that there are 737226 days between ‘2018-06-15’ and 0 AD.