FROM_DAYS() Function in MySQL

• Difficulty Level : Medium
• Last Updated : 11 Jan, 2021

FROM_DAYS() :

This function is used to return the date from a specified numeric date value. Here specified date value is divided by 365 and accordingly years, months, and days are returned. This function is used only with dates within the Gregorian calendar.

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

Features :

• This function is used to find a date from a specified numeric date value.
• This function accepts a single parameter.
• Here the accepted parameter is a specified numeric day to convert to date.
• This function is used only with dates within the Gregorian calendar.

Syntax :

`FROM_DAYS(number)`

Parameters :

This function accepts only one parameter.

• number – Specified numeric day to convert to a date

Returns :

It returns a date from a specified numeric date value.

Example-1 :

Getting a date of “0001-01-01” within the Gregorian calendar from a specified numeric date value “366”. Here the specified date value 366 is divided by 365 which gives the remainder as 1, so returned year is 0001 of 1st January month.

`SELECT FROM_DAYS(366);`

Output :

`0001-01-01`

Example-2 :

Getting a date of “0001-01-15” within the Gregorian calendar from a random numeric date value between 366 and 400.

Here for getting parameter date value, FLOOR() function is used which will return date value in between 366 and 400. Then using this returned date value, FROM_DAYS() function will return the date of “0001-01-15”.

`SELECT FROM_DAYS(FLOOR(366 + RAND()*(400 - 366 + 1)));`

Output :

`0001-01-15`

Example-3 :

Getting a date of “0002-09-27” within the Gregorian calendar from a numeric date value “1000”. Here the date value “1000” is returned from the POWER() function and then FROM_DAYS() function takes this value as parameter and returns a date of “0002-09-27”.

`SELECT FROM_DAYS(POWER(10, 3));`

Output :

`0002-09-27`

Example-4 :

Getting a date of “0001-03-08” within the Gregorian calendar from a numeric date value “432.2”. Here the date value “432.2” is the absolute value of “-432.2” which is returned by the ABS() function. The returned absolute value “432.2” is taken as the parameter of FROM_DAYS() function which gives the date of “0001-03-08” as returned value.

`SELECT FROM_DAYS(ABS(-432.2));`

Output :

`0001-03-08`

Application :

This function is used to returns a date from a specified numeric date value.

My Personal Notes arrow_drop_up