MySQL FROM_DAYS() Function Example

MySQL FROM_DAYS() Function Example

MySQL FROM_DAYS() function; In this tutorial, we would love to share with you how to use MySQL from_days function with the help of examples.

MySQL FROM_DAYS() Function

In MySQL, the FROM_DAYS() the function is used to returns a date value based on the number of days provided as a parameter or argument.

Syntax

The basic syntax of the FROM_DAY function is:

FROM_DAYS(N)

HereN is the number of days from day 0.

Example-1

Let’s take the first example for a demonstration.

SELECT FROM_DAYS(367);

Output-1

+----------------+
| FROM_DAYS(367) |
+----------------+
| 0001-01-02     |
+----------------+

Note however that the MySQL documentation advises that this function is not for use with those values ​​that were before the arrival of the Gregorian calendar (1582).

Example-2

Now we take a second example with a later date:

SELECT FROM_DAYS(650000);

Output-2

+-------------------+
| FROM_DAYS(650000) |
+-------------------+
| 1779-08-22        |
+-------------------+

Example-3

Let’s take another example with a later date again:

SELECT FROM_DAYS(750000);

Output-3

+-------------------+
| FROM_DAYS(750000) |
+-------------------+
| 2053-06-06        |
+-------------------+

Example-4

FROM_DAYS() v/s TO_DAYS()

Contrary to the FROM_DAYS () function TO_DAYS (), which returns the number of days, given a date. Here’s an example to display the relationship between FROM_DAYS () and TO_DAYS () functions:

    SELECT 
    CURDATE(),
    TO_DAYS(CURDATE()),
    FROM_DAYS(TO_DAYS(CURDATE()));

Output-4

+------------+--------------------+-------------------------------+
| CURDATE()  | TO_DAYS(CURDATE()) | FROM_DAYS(TO_DAYS(CURDATE())) |
+------------+--------------------+-------------------------------+
| 2019-07-16 |             737621 |  2019-07-16                   |
+------------+--------------------+-------------------------------+

So in this example, we use TO_DAYS () to return the number of days from the current date. Then I use FROM_DAYS () to return the date from that value (which, as expected, returns to the original value of CURDATE ()).

Conclusion

Here, you have learned how to use MySQL FROM_DAYS() function. You have also learned different FROM_DAYS () and TO_DAYS () function of MySQL.

Recommended MySQL Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *