FROM_DAYS() Function Examples – MySQL

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 MySQL 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 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.

You may like

  1. WEEKOFYEAR() Function Examples – MySQL
  2. WEEKDAY() Function Examples – MySQL
  3. LAST_DAY MySQL Function Examples
  4. DAYOFYEAR() Function Examples – MySQL
  5. MySQL YEARWEEK() Function Examples – MySQL
  6. MySQL weekday function with example
  7. MySQL CURRENT TIMESTAMP Function Examples
  8. Get month name from date in mysql
  9. mysql get first day of the current month
  10. mysql last day of previous month
  11. Get month number from month name in mysql
  12. mysql get day of week number from date
  13. Mysql Get Data Of Current Date, Week, Month, YEAR
  14. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql

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

Leave a Reply

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