The DATEDIF function in Google Sheets is a powerful tool designed to compute the difference between two dates in various units of time, including days, months, and years. It is particularly useful for age calculations, project timelines, and date comparisons, allowing users to obtain accurate results with minimal effort.
Syntax
DATEDIF(start_date, end_date, unit)
- start_date: The initial date from which the calculation begins.
- end_date: The final date to which the calculation is made.
- unit: The unit of measure for the result, which can be “D” for days, “M” for months, or “Y” for years.
Example #1
DATEDIF("2020-01-01", "2020-01-31", "D")
This function will calculate the number of days between January 1 and January 31 of 2020, resulting in 30.
Example #2
DATEDIF("2015-05-15", "2020-05-15", "Y")
This function will determine the number of complete years between May 15, 2015, and May 15, 2020, yielding a result of 5.
Example #3
DATEDIF("2018-01-01", "2020-12-31", "M")
This function will calculate the total number of complete months between January 1, 2018, and December 31, 2020, providing a result of 35.
Error handling
- VALUE!: This error appears when the input dates are incorrect or not in a recognizable format, indicating that the function cannot perform the calculation.
- NUM!: This message occurs if the start_date is later than the end_date, showing that a valid range for calculation has not been provided.