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.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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