w3resource

MySQL Date and Time Exercises: Get the DATE value from a given day

MySQL Date Time: Exercise-10 with Solution

Write a MySQL query to get the DATE value from a given day (number in N).

Sample days: 730677
Output: 2000-07-11

Code:

-- This SQL query converts a number representing the number of days since year 0 to a date value.

SELECT 
    FROM_DAYS(730677);

Explanation:

  • The FROM_DAYS() function in MySQL is used to convert a number representing the number of days since year 0 to a date value.
  • In this query, the number 730677 is provided as an argument to the FROM_DAYS() function.
  • This number represents the number of days since year 0.
  • The result of this query will be the corresponding date value for the provided number of days.

Sample Output:

FROM_DAYS(730677)
2000-07-11T04:00:00.000Z

Go to:


PREV :Write a MySQL query to extract the year from the current date.
NEXT :Write a MySQL query to get the first name and hire date from employees table where hire date between '1987-06-01' and '1987-07-30'.

MySQL Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.