4 ways to calculate the duration between two dates - Data Cycle Analytics (2024)

In any working environment, there are various instances where you would be required to calculate the duration between two dates.

A human resource officer would need to know how long a given employee has worked with the company or the actual age of the various employees for planning purposes. In an automotive industry, you would need to compute how long, say a given vehicle has taken to be serviced. For most NGOs, it would be needful to know, based on the contractual terms of various consultants, how many months/years are remaining and subsequently, how many employees have their contracts ending, say in the next 3 months, 6 months, and so on.

There are many ways that you can achieve to calculate the difference between any two dates in Excel.

For this example, we shall discuss how to calculate the length of service of various employees as at a given date, but the concept applies in all the scenarios described above.

Calculate the duration of service of employees

We have the following subset of data extract.

4 ways to calculate the duration between two dates - Data Cycle Analytics (1)

In cell C2 we shall type a date as at which we shall compute the length of service. This can be (1) a date that you hardcode, or (2) a date representing today’s date, or (3) a formula that returns the end of the previous month with reference to today’s date.

To always use the current (i.e. today’s) date, type the following in cell C2:

=TODAY( )

The Excel’s TODAY function will always return the current date.

To always use the end of the previous month with reference to today’s date, we shall type the following in C2:

=EOMONTH (TODAY( ), -1)

The EOMONTH function normally returns a serial number that represents the end of the month, “x” number of months before or after the specified date. The number of months before or after can be a positive number or a negative number or zero if you want to return the end of the current month. For instance, if the TODAY function wrapped inside this formula is assumed to be “8/8/2017” then using 0 as the last parameter will result in “31/8/2017”, using -2 will return “30/6/2017” whereas using a +4 will yield “31/12/2017”

In this example, we shall enter this EOMONTH function in cell C2 to always consider the end of the previous month.

Different approaches to compute differences between two dates

Let us explore various methods to calculate the duration between two dates.

Method 1: Subtract the two dates

The obvious method I have seen with various trainees is to subtract the date of joining from the specified end date and then divide the resultant value by 365 (or 360 for other regions) as shown below.

4 ways to calculate the duration between two dates - Data Cycle Analytics (2)

The equivalent of the formula shown in cell E5 above would be = DAYS ($C$2, D6)/365 which would give similar results.

Method 2: Subtract the years

In this approach, we assume we just need to compute the difference between the two dates as whole years, as is the case when you want to compute your age as at the last birthday.

We therefore employ the formula shown in the figure below.

4 ways to calculate the duration between two dates - Data Cycle Analytics (3)

This approach rounds the result to the nearest whole number.

Method 3: Using the YEARFRAC function

This method gives similar results with the first method above. That is, it will compute the fractional year differences between two dates.

For instance, if the last day is “31/07/2017” and you joined the company on “27/09/1998” then the formula will compute the difference taking into account differential months. So, whereas method 2 would give 19 as the difference in years, YEARFRAC will yield 18.84.

Take a look.

4 ways to calculate the duration between two dates - Data Cycle Analytics (4)

Notice that in this case you start by specifying the date of joining in the formula.

Let us compare the results

The figure that follows compares the output of the various approaches discussed so far.

4 ways to calculate the duration between two dates - Data Cycle Analytics (5)

Method 4: Using DATEDIF function

When you type DATEDIF as you would do with any other formulas, this formula doesn’t show a prompt (normally called the intellisense) as other formulas do. It was popular in earlier Excel versions 2003 and earlier) but has since not been given a lot of focus. I guess Microsoft might stop supporting it very soon (my guess).

This function computes the difference in either the completed/full years, months or days, between two dates. Just like the YEARFRAC function, it also requires you to specify the starting and the ending date. However, you would need to specify the time unit of output, in terms of years, months or days.

Syntax: DATEDIF (Start_date, End_date, Unit)

There are six different outputs that you can get based on the time unit you specify as follows:[/vc_column_text][gem_table]

Unit
Output
“y”Difference in terms of complete years
“m”Difference in terms of complete months
“d”Difference in terms of complete days
“yd”Returns the difference of complete days, ignoring the ones in the years that have been completed. Simply put, for the specified start date, it takes the equivalent date in the immediate previous year as the basis of subtracting the completed days
“ym”Returns the difference of complete months, ignoring the ones in the years that have been completed. It takes the immediate previous year as the basis of subtracting the full months
“md”This interval just subtracts the day part of the two dates. For instance, in the table below, notice the “md” column is the difference between the day element of the two dates. In row 9 for example it is 31-1=30

The figure below illustrates all the six possible outputs.

4 ways to calculate the duration between two dates - Data Cycle Analytics (6)

In conclusion

The various approaches discussed above are enough arsenals for various scenarios you may encounter. Should you have comments or questions regarding manipulating dates in Excel, please lodge them in the comments area below.

Please share the article with your colleagues and let them improve how they work with Excel.

4 ways to calculate the duration between two dates - Data Cycle Analytics (2024)
Top Articles
Sign in to the Gemini web app
Your Viral Video: Does Length Really Matter? - Demo Duck
Ron Martin Realty Cam
Parke County Chatter
Zabor Funeral Home Inc
What happened to Lori Petty? What is she doing today? Wiki
Wal-Mart 140 Supercenter Products
Cinepacks.store
Osrs But Damage
Nonuclub
Oscar Nominated Brings Winning Profile to the Kentucky Turf Cup
Shemal Cartoon
Nioh 2: Divine Gear [Hands-on Experience]
Healing Guide Dragonflight 10.2.7 Wow Warring Dueling Guide
Walmart Windshield Wiper Blades
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
Walmart Double Point Days 2022
Lake Nockamixon Fishing Report
Straight Talk Phones With 7 Inch Screen
Ou Class Nav
Katherine Croan Ewald
Skyward Login Jennings County
Why do rebates take so long to process?
Food Universe Near Me Circular
Used Safari Condo Alto R1723 For Sale
Company History - Horizon NJ Health
Sister Souljah Net Worth
Il Speedtest Rcn Net
Hefkervelt Blog
Best Town Hall 11
Viduthalai Movie Download
Housing Intranet Unt
Spy School Secrets - Canada's History
Teenbeautyfitness
Hair Love Salon Bradley Beach
2016 Honda Accord Belt Diagram
The Mad Merchant Wow
Rage Of Harrogath Bugged
Toth Boer Goats
How to play Yahoo Fantasy Football | Yahoo Help - SLN24152
Gvod 6014
Verizon Outage Cuyahoga Falls Ohio
The Conners Season 5 Wiki
Devon Lannigan Obituary
Executive Lounge - Alle Informationen zu der Lounge | reisetopia Basics
Gotrax Scooter Error Code E2
Costco Gas Foster City
French Linen krijtverf van Annie Sloan
SF bay area cars & trucks "chevrolet 50" - craigslist
60 Second Burger Run Unblocked
Wild Fork Foods Login
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5670

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.