MySQL FROM_DAYS() Function
The FROM_DAYS()
function in MySQL converts a numeric representation of a date (number of days since year 0) into a date value. This is useful when working with dates stored as day numbers.
FROM_DAYS(): Definition and Usage
FROM_DAYS()
takes an integer representing the number of days since the date "0000-00-00" (year 0) and returns the corresponding date. It's important to note that this function is specifically designed for the Gregorian calendar and might not be accurate for dates outside the Gregorian calendar system.
Syntax
Syntax
FROM_DAYS(number)
Parameter Values
Parameter | Description |
---|---|
number |
The number of days since year 0. This is required and must be an integer. |
Related Function
The opposite of FROM_DAYS()
is the TO_DAYS()
function, which converts a date to the number of days since year 0.
Examples
Converting a Day Number to a Date
This example converts the day number 685467 to a date.
Syntax
SELECT FROM_DAYS(685467);
Output
2017-06-20
Converting Another Day Number to a Date
This example demonstrates converting a different day number.
Syntax
SELECT FROM_DAYS(780500);
Output
2021-06-20