Close this search box.

How to calculate time between two dates in Years, Months & Days [Excel Formula]


time between two dates excel formula

Let’s say you have two dates in the cells D4 & D5 as above. You want to find out the duration in years, months & days between both. We can use the good-old DATEDIF formula for this.


'All in one formula: 
=DATEDIF($D$4,$D$5,"y")&" years "&DATEDIF($D$4,$D$5,"ym")&" months "&DATEDIF($D$4,$D$5,"md")&" days"

Using LAMBDAs to create a custom function for this

We can use Excel’s LAMBDA functions to create a custom duration function to get the duration in years, months & days from any two dates.

This feature is available with Excel 365. 

Here is one such formula.

					=LAMBDA(start,end, LET(y, DATEDIF(start,end,"y"), m,  DATEDIF(start,end,"ym"), d,  DATEDIF(start,end,"md"), y &" years "&m&" months "&d&" days"))


Setting up this LAMBDA getDuration() Function in your Excel

To use this LAMBDA function in your Excel, 

  1. Go to Formula Ribbon > Name Manager
  2. Click on New Name
  3. Type the name as getDuration
  4. Type Refers to as the above LAMBDA function
  5. Click OK

Now, you will have a getDuration() function in your Excel!
To use it, just type=getDuration(start,end) in any cell.

Calculating Other Types of Durations in Excel

Refer to below formulas to calculate other kinds of duration in Excel. All of these formulas assume you have start & end dates in cells D4 & D5.

Duration in DAYS



Duration in WORKING DAYS (Monday to Friday)


Duration in WORKING DAYS (Custom Weekend)

If you have a custom weekend type (for example, Friday, Saturday weekend), you can use the NETWORKDAYS.INTL function like this to calculate the duration in working days.

Both of these functions (NETWORKDAYS, NETWORKDAYS.INTL) also accept an optional list of holidays (such as Christmas, New Years day etc.) to handle arbitrary holidays.

'calculates working days between D4 & D5 with Tuesday, Wednesday weekend policy!

Number of Months

					=DATEDIF(D4, D5, "m")

Duration in Years

'calculates the duration in years with leap year logic.

Try these formulas yourself

Click here to download the SAMPLE FILE with all these duration calculations. 

To use the LAMBDA function, you need Excel 365. 

More on Duration Calculation in Excel


Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Excel School made me great at work.

– Brenda

Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

Leave a Reply