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

FROM_DAYS(value)

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

Examples

SELECT FROM_DAYS((365.25*2008))
AS 'Start of 2008?', FROM_DAYS(366);

+----------------+
| Start of 2008? |
+----------------+
| 2008-01-16     | 
+----------------+

Assuming that there are 365.25 days in a year on average (allowing for the leap year), you would think that multiplying that factor by 2008 would give a result of January 1, 2008, but it doesn't because of the calendar changed centuries ago. This function is possibly useful for comparing dates and displaying the results in a readable format. However, since there are many other functions available in MySQL, its usefulness is fairly diminished.

SELECT CURDATE( ) As 'Now', 
TO_DAYS(NOW( )) AS 'Days since Day 0', 
FROM_DAYS(TO_DAYS(NOW( )) + 7) AS '7 Days from Now', 
ADDDATE(CURDATE( ), 7) AS 'Simpler Method';

+------------+------------------+-----------------+----------------+
| Now        | Days since Day 0 | 7 Days from Now | Simpler Method |
+------------+------------------+-----------------+----------------+
| 2007-03-14 |           733114 | 2007-03-21      | 2007-03-21     | 
+------------+------------------+-----------------+----------------+