TO_DAYS()
TO_DAYS(date)This function returns the date based on the number of days given, which are from the beginning of the currently used standard calendar. Problems occur for dates before 1582, when the Gregorian calendar became the standard. The opposite of this function is FROM_DAYS(). Here is an example:
SELECT CURDATE( ) AS 'Today',
TO_DAYS('2008-12-31'),
TO_DAYS(CURDATE( )),
(TO_DAYS('2008-12-31') -
TO_DAYS(CURDATE( )))
AS 'Days to End of Year' \G
*************************** 1. row ***************************
Today: 2008-11-03
TO_DAYS('2007-12-31'): 733772
TO_DAYS(CURDATE( )): 733714
Days to End of Year: 58In this example, the TO_DAYS() function
is used to calculate the difference in the number of days between the
two dates, the number of days from the current date until the year’s
end. I’ve used the \G ending instead of the
semicolon so as to save space horizontally.