TO_DAYS( )

This MySQL function returns the date based on the number of days given, which are from the beginning of the currently used standard calendar.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

TO_DAYS(date)

Explanation

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( ).

Examples

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: 58

In this example, the TO_DAYS( ) function is employed to calculate the difference in the number of days between the two dates, the number of days from the current date until the year-end. I've used the G ending instead of the semi-colon so as to save space horizontally.