MySQL FROM_DAYS() Function
The MySQL FROM_DAYS() function takes a numeric representation of the day and returns a date value.
This function is to be used only with dates within the Gregorian calendar.
Note: The TO_DAYS() function which is the reverse of the FROM_DAYS() function.
Syntax
FROM_DAYS(numeric_day)
Parameters
numeric_day |
Required. Specify the numeric day to convert to a date. |
Return Value
Returns the date converted from numeric days.
Example 1:
The example below shows the usage of FROM_DAYS() function.
mysql> SELECT FROM_DAYS(737289); Result: '2018-08-18' mysql> SELECT FROM_DAYS(737290); Result: '2018-08-19' mysql> SELECT FROM_DAYS(737291); Result: '2018-08-20'
Example 2:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Numeric DOJ |
---|---|---|---|---|
1 | John | London | 25 | 737204 |
2 | Marry | New York | 24 | 737347 |
3 | Jo | Paris | 27 | 737584 |
4 | Kim | Amsterdam | 30 | 737688 |
5 | Ramesh | New Delhi | 28 | 737722 |
6 | Suresh | Mumbai | 28 | 738515 |
The statement given below can be used to convert the records of column [Numeric DOJ] into a date:
SELECT *, FROM_DAYS(`Numeric DOJ`) AS Date_of_Joining FROM Employee;
This will produce the result as shown below:
EmpID | Name | City | Age | Numeric DOJ | Date_of_Joining |
---|---|---|---|---|---|
1 | John | London | 25 | 737204 | 2018-05-25 |
2 | Marry | New York | 24 | 737347 | 2018-10-15 |
3 | Jo | Paris | 27 | 737584 | 2019-06-09 |
4 | Kim | Amsterdam | 30 | 737688 | 2019-09-21 |
5 | Ramesh | New Delhi | 28 | 737722 | 2019-10-25 |
6 | Suresh | Mumbai | 28 | 738515 | 2021-12-26 |
❮ MySQL Functions