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

 

MySQL Code Editor:

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

Previous: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'.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mysql-exercises/date-time-exercises/write-a-query-to-get-the-date-value-from-a-given-day-number-in-n.php