Calculating months, days, hours, minutes, seconds in Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-1287209%22%20slang%3D%22en-US%22%3ECalculating%20months%2C%20days%2C%20hours%2C%20minutes%2C%20seconds%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1287209%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20to%20calculate%20months%2C%20days%2C%20hours%2C%20minutes%20and%20seconds%20from%20date%2Ftime%20stamps%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20time%3A%26nbsp%3B4%2F29%2F2019%26nbsp%3B%2011%3A36%3A59%20AM%20(minus)%20Start%20time%3A%203%2F27%2F2019%26nbsp%3B%202%3A27%3A52%20AM%20%3D%20Active%20time%20(in%20months%2C%20days%2C%20hours%2C%20minutes%20and%20seconds)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20about%2020%2C000%20start%2Fend%20date%2Ftime%20stamps%20that%20I%20need%20to%20calculate%20into%20months%2C%20days%2C%20hours%2C%20minutes%20and%20seconds.%20Once%20this%20is%20complete%2C%20I%20need%20to%20find%20the%20average%20Active%20time%20(suggestions%20on%20how%20to%20do%20this%20are%20very%20welcome%20too).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20DATEDIF%20function%2C%20INT%20function%20as%20well%20as%20using%20Cell%20Format.%20I%20can%20get%20part%20of%20what%20I%20need%2C%20but%20not%20all.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3EThanks%20so%20much!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1287209%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1287399%22%20slang%3D%22en-US%22%3ERe%3A%20Calculating%20months%2C%20days%2C%20hours%2C%20minutes%2C%20seconds%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1287399%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F612058%22%20target%3D%22_blank%22%3E%40Jo_666%3C%2FA%3E%26nbsp%3BTo%20begin%20with%2C%20I%20would%20suggest%20you%20forget%20about%20the%20number%20of%20months%20in%20your%20calculation.%26nbsp%3B%3C%2FP%3E%3CP%3E%22One%20month%22%20becomes%20rater%20vague%20as%20it%20may%20be%2028%2C%2029%2030%20or%2031%20days%20long%20depending%20on%20the%20month%20and%20year.%20If%20you%20then%20want%20to%20come-up%20with%20some%20overall%20average%20of%20your%2020000%20sets%20of%20date%2Ftime-stamps%2C%20you%20could%20say%20%22it's%2040%20days%20and%2010%20hrs%22%20and%20translate%20that%20to%20%22roughly%20one%20month%20plus%2010%20and%20a%20half%20days%22.%3C%2FP%3E%3CP%3EHave%20attached%20an%20example%20for%20your%20reference.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1289011%22%20slang%3D%22en-US%22%3ERe%3A%20Calculating%20months%2C%20days%2C%20hours%2C%20minutes%2C%20seconds%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1289011%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20so%20much%20for%20your%20help.%20You're%20right%2C%20dropping%20months%20is%20the%20way%20to%20go%20and%20made%20things%20much%20easier.%20I've%20got%20it%20sorted%20now.%20Really%20appreciate%20the%20help!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1289405%22%20slang%3D%22en-US%22%3ERe%3A%20Calculating%20months%2C%20days%2C%20hours%2C%20minutes%2C%20seconds%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1289405%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F612058%22%20target%3D%22_blank%22%3E%40Jo_666%3C%2FA%3E%26nbsp%3BGlad%20I%20could%20help!%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I need to calculate months, days, hours, minutes and seconds from date/time stamps: 

 

End time: 4/29/2019  11:36:59 AM (minus) Start time: 3/27/2019  2:27:52 AM = Active time (in months, days, hours, minutes and seconds)

 

I have about 20,000 start/end date/time stamps that I need to calculate into months, days, hours, minutes and seconds. Once this is complete, I need to find the average Active time (suggestions on how to do this are very welcome too).

 

I've tried DATEDIF function, INT function as well as using Cell Format. I can get part of what I need, but not all.

 

Thanks so much! 

14 Replies

@Jo_666 To begin with, I would suggest you forget about the number of months in your calculation. 

"One month" becomes rater vague as it may be 28, 29 30 or 31 days long depending on the month and year. If you then want to come-up with some overall average of your 20000 sets of date/time-stamps, you could say "it's 40 days and 10 hrs" and translate that to "roughly one month plus 10 and a half days".

Have attached an example for your reference.

 

 

@Riny_van_Eekelen 

 

Thanks so much for your help. You're right, dropping months is the way to go and made things much easier. I've got it sorted now. Really appreciate the help!

@Riny_van_Eekelen 

 

Any chance you can also tell me how to also include ways to exclude weekend and holidays?

@Ok-Feature-4243 You need to look into the NETWORKDAYS.INTL function. It allows for excluding both weekends and holidays.

@Riny_van_Eekelen 

 

My understanding, workday.intl function is to find the date, after a certain days from the starting date.

 

That said, I should already know the number of days, I just don't know when the ending date and workday.intl can tell me when the ending date in this scenario. Is my understanding correct?

 

In my case, I have start date and ending date, what I do not know is the number of days and hours and the average days/hours between the two dates.

 

Any chance you can show me by using the same file that you attached on your previous message on this thread on how workday.intl can works in calculating days and hours and the average between starting and end date? 

@Ok-Feature-4243 My earlier file had nothing to do with NETWORKDAYS.INTL. Not really sure what you are after. Better to start a new conversation and include an example file of what you are dealing with and what results you need. 

@Riny_van_Eekelen 

 

I know that your earlier file had nothing to do with NETWORKDAYS.INTL, but your earlier file is exactly the file that I'm currently having and what I'm trying to achieve. 

 

I have starting and ending date in yyyy-mm-dd h:mm format and I need to calculate the time difference between the two dates in days, hours and minutes excluding weekend/holiday and finally the average time difference.

 

I tried to use NETWORKDAYS.INTL but it didn't work =NETWORKDAYS.INTL(A2,E2,1,{"2020/9/7","2020/10/12","2020/11/11","2020/12/25","2020/12/28","2021/1/1","2021/2/15","2021/4/2,"2021/5/24","2021/7/1","2021/8/2","2021/9/6","2021/10/11","2021/11/11","2021/12/27","2021/12/28"})

 

A2 = 

2020-08-10 9:46

 

E2 = 

2020-08-11 9:46

 

@Riny_van_Eekelen 

 

I get rid of 2021 holidays =NETWORKDAYS.INTL(A2,E2,1,{"2020/9/7","2020/10/12","2020/11/11","2020/12/25","2020/12/28"}) and the result between 

 

2020-08-10 9:46

and

2020-08-11 9:46

 

= 2

 

When I get rid of the holidays, result remain the same. 

 

I don't think this is correct. Much appreciated if you could provide answer. 

 

@Riny_van_Eekelen 

 

I know what happen but I don't know how to fix it. 

 

I modified the formula a bit by listing all the holidays on column I =NETWORKDAYS.INTL(A2,E2,1,$I$2:$I$6) but still getting the same incorrect result. 

 

So, Aug 10 2020 was Monday and Aug 11 2020 was Tuesday. The result showing 2 days which is incorrect, however, the same formula works correctly (to exclude weekend/holiday) when the 2 dates are over the weekend. The formula is not working correctly when the 2 dates is not over the weekend. 

 

What would be the solution to this? Thx!

@Ok-Feature-4243 

NETWORKDAYS.INTL includes the start date and end date in the count, if they are working days.

In your example, since Monday and Tuesday are both working days, the result is 2.

If you want to exclude the start date from the count, use

 

=NETWORKDAYS.INTL(A2,E2,1,$I$2:$I$6)-NETWORKDAYS.INTL(A2,A2,1,$I$2:$I$6)

 

Remark: the result is only meaningful if E2>=A2

@Hans Vogelaar 

The formula does correctly counting the number of days but the same issues is still not being solved.

 

The formula still can't counting the number of days when the 2 dates are over the weekend which I believe is what NETWORKDAYS.INTL is for. 

 

On the following 2 dates:

2020-09-04 13:50

and

2020-09-07 13:50

 

I use =NETWORKDAYS.INTL(A26,E26,1,$I$2:$I$6)-NETWORKDAYS.INTL(A26,A26,1,$I$2:$I$6)+MOD(E26-A26,1)

 

I use MOD function to show the hours and the result for the above 2 dates = 0

@Ok-Feature-4243

It is 0 because 2020-09-07 was a public holiday according to one of your earlier posts.

@Hans Vogelaar 

 

You are correct! And I'm embarrassing myself

 

Thx all!