FROM_DAYS() Function Examples – MySQL

In this MySQL FROM_DAYS() tutorial, we would love to share with you how to use MySQL FROM_DAYS() function with various examples. Today we are going to show you uses and syntax of FROM_DAY() function with 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() 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.

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

Spread the love

Be First to Comment

Leave a Reply

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