Open In App

TO DAYS() FUNCTION in MySQL

Last Updated : 08 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

TO DAYS() :

TO DAYS() function in MySQL takes the given date and returns a number of days since year 0 corresponding to the given date.
TO DAYS() function can only be used with the dates within the Gregorian calendar.

Syntax :

TO DAYS(date)

Parameters: The function can accept only one argument as shown below-

  • date – the given date to be converted.

Return :

The function will return a day number representing the total no of days till the given date

Example 1:

Working of TO DATE() function with given date number.

SELECT TO_DAYS(950510);

Output: 

TO_DAYS(950510)

728788

Example 2:

Working of TO DATE() function with given date format(‘YYYY-MM-DD’)

SELECT TO_DAYS('2020-12-26');

Output:

TO_DAYS(‘2020-12-26’)

738150

Example 3:

Working of TO DATE() function with given date format(‘YY-M-D’),

NOTE – Mentioning the year in full number is not important as shown in this example-

SELECT TO_DAYS('3-4-21');

Output:

TO_DAYS(‘3-4-21’)

1206

Example 4:

Working of TO DATE() function with given date format(‘YY-M-D’) and time.

SELECT TO_DAYS('0000-00-00');

Output:

TO_DAYS(‘0000-00-00’)

NULL


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads