The DATEDIFF()
function returns the number of days between two dates sent as parameter.
Figure 1 shows a visual representation of the DATEDIFF()
function.
DATEDIFF(date-1, date-2)
The DATEDIFF()
function takes two dates
as a parameter.
Dates must be in the format YYYY-MM-DD, or this function returns
NULL
.
The DATEDIFF()
function returns the number of days between two dates sent as a parameter.
This function only uses the date portion if the datetime is sent instead of date.
-- date1>date2SELECT DATEDIFF('2021-07-10','2021-07-09');-- date1<date2SELECT DATEDIFF('2021-07-10','2021-07-12');-- datetimeSELECT DATEDIFF('2021-07-10 07:15:11','2021-07-09 09:24:31');-- date in wrong formatSELECT DATEDIFF('10-07-2021','09-07-2021');