Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel's DATEDIF() Function - Syntax and Examples 2

Status
Not open for further replies.

Bowers74

MIS
Nov 20, 2002
1,085
US
Another way to calculate dates in Excel, is a function that has absolutely no documentation in the Excel Help File (except Excel 2000). This function is the DATEDIF() function. It originates from Lotus 1-2-3.

The DATEDIF() function uses the following syntax:

=DATEDIF(start_date,end_date,"unit_code")

The start date has to be less than the end date, or else the function will return an error.

The following are the Unit Codes for the DATEDIF() function:

1. "y" - The years in a period
2. "m" - The months in a period
3. "d" - The days in a period
4. "md" - The difference between the days in a period, w/o the months and years
5. "ym" - The difference between the months in a period, w/o the days and years
6. "yd" - The difference between the days in a period, w/o the years

To calculate the number of years between two dates

=DATEDIF(A1,TODAY(),"y") & " Years"

To calculate the number of years and months between two dates

=DATEDIF(A1,TODAY(),"y") & " Years, " & DATEDIF(A1,TODAY(),"ym") & " Months"

To calculate the number of years, months and days between two dates

=DATEDIF(A1,TODAY(),"y") & " Years, " & DATEDIF(A1,TODAY(),"ym") & " Months, " & DATEDIF(A1,TODAY(),"md") & " Days"


I posted this inside a FAQ I wrote that deals with some of the Date Functions in Excel. If you're interested, then check it out:

faq68-4037




Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
I use to use this in 1-2-3, but never knew that it was in excel too.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top