Name
FROM_DAYS()
Synopsis
FROM_DAYS(value)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 TO_DAYS(). Here is an example:
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 change 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. Here is an example:
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 | +------------+------------------+-----------------+----------------+
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access