Google Sheets Function: DATEDIF
The DATEDIF function calculates the number of days, months, or years between two dates.
Usage:
=DATEDIF(start_date, end_date, unit)
Number of days between 2 dates
To get the number of days between "12/15/2023" and "2/26/2024", enter these dates into the DATEDIF function along with the unit "D" to return the number of days:
=DATEDIF("12/15/2023","2/26/2024","D")

If the dates are in cells, enter:
=DATEDIF(B1,B2,"D")

Note that in this case, you could also simply enter:
=B2-B1

Number of complete months between 2 dates
To get the number of complete months between 2 dates, enter the unit "M":
=DATEDIF(B1,B2,"M")

Number of complete years between 2 dates
To get the number of complete years between 2 dates, enter the unit "Y":
=DATEDIF(B1,B2,"Y")
