MySQL TO_DAYS is one of the Date Functions, which returns the total number of days from year 0 to the user-given date. The syntax of the TO_DAYS Function is as shown below:
MySQL TO_DAYS function Example
The following examples help you understand the use of the To days method. Here, we are returning the total number of days from 0 to different dates.
TO DAYS Example 2
In this example, we are using NOW, CURDATE, along with some additional operations inside this TO_DAYS function. It means we are using the MySQL Date value in String format.
SELECT TO_DAYS(CURDATE()), TO_DAYS(CURDATE() + 2);
Let us see another query of it and this time, we are using the YYMMDD format as the argument. From the below Date method example, 19 means 2019
The TO_DAY function will throw an error if it finds the Wrong Date Or Zero. This example shows you the same. Within the third statement, we are using the YYMMDD, and we know 36 days is the wrong value.