Formula for Total hours between two date times in ms excel - excel-formula

I need to calculate the total hours and minutes between two dates mentioned in excel. i.e.,
Start date: 02-Sep-2013 02:03:00 AM
End Date: 04-Sep-2013 02:04:00 AM
The answer should be 48:01 h:mm.
Need to consider holidays also, like if 03-Sep-2013 is holiday, then
The answer should be 24:01 h:mm.
There are no business hours. It should consider 24 hours. Please help me on this.

a simple subtraction will get you the value you want: subtract one date/time from the other, and then subtract the number of holiday dates that fall between the two dates.
the trick is to format the result cell as [h]:mm (this format works for up to 9999 hours)
Here's an example:

Hours = ((End_Date+End_Time)-(Start_Date+Start_Time))*24
For more details please refer the below link
Excel
Another Formula with example
Cell A1: 2/15/2012 10:00:00 AM
Cell B1: 2/18/2012 08:00:00 PM
What is the elapsed time between both dates (in hours)?
You can get the answer by using the below formula in cell
C1:= INT(B1-A1)*24+(((B1-A1)-INT(B1-A1))/0.04166666)

The problem with many of the example answers given is definitional. If you are looking for elapsed time finer than days in significant digits the "B2-B1" answer given is incorrect if the end time is earlier in the day than the start time.
Depending on what I am trying to extract I use variations of the following formula to get a more precise "elapsed time". Depending on why a person lands on this answer the difference in result can make a difference.
=ROUNDDOWN(B3-B2,0) & " Days "
& ROUNDDOWN(MOD(B3-B2,1)*24,0) & " hours "
& TEXT(MOD(MOD(B3-B2,1)*24,1)*60,"#0") & " Mins"
(formatted for easier reading)
The image below shows the results of the different answers proposed. I am not saying the other answers are wrong just that they may not be precise enough depending on the purpose of the answer seeker.

Related

Show Current Time in Excel by Timezone

I have searched all over and any answer or code I find is rather confusing.
I am looking to convert the =NOW function in excel to a different timezone(s)
I am currently using
=TEXT(NOW(), "hh:mm:ss AM/PM")
which displays my timezone EST
I would like to convert this to another time zone
for example PST.
is there a way to do
=TEXT IF C1 equals PST subtract 3 from A1 <--- the current time
what im trying to do is if one column has the letters PST in it I want to convert the =NOW by subtracting 3 hours from my EST Time Zone.
sorry if my question is a little confusing.
I know im not the only one searching this so an answer would help me and future users, thanks so much in advance.
UPDATE:
so I was able to use
=TEXT(NOW()-0.125, "hh:mm:ss AM/PM")
to subtract 3 hours, but not make an if statement for 2 or more timezones
What about when day light savings occurs. You want to use the HOURS() function in Excel and subtract the necessary hours for each times zone. You'll also need to handle crossing midnight in your calculation. If you just want to play around with what you have started see the below link for something more accurate to your stated post.
Check this link add and subtract time in excel
Try this:
=IF(B3="PST", =TEXT(NOW()-0.125, "hh:mm:ss AM/PM") ,=TEXT(NOW()))
Try this formula in B3 cell for individual
=TEXT(NOW()-TIME(hour,minute,second),"hh:mm:ss AM/PM")
and by using IF statement for 2 or more timezones in B6 cell
=IF(B1="GST",TEXT($A$1-TIME(1,30,0),"hh:mm:ss AM/PM"),
IF(B1="BST",TEXT($A$1-TIME(4,30,0),"hh:mm:ss AM/PM"),
IF(B1="EST",TEXT($A$1-TIME(9,30,0),"hh:mm:ss AM/PM"),
IF(B1="PST",TEXT($A$1-TIME(12,30,0),"hh:mm:ss AM/PM"),
IF(B1="AST",TEXT($A$1-TIME(6,30,0),"hh:mm:ss AM/PM"),
IF(B1="ACST",TEXT($A$1-TIME(2,30,0),"hh:mm:ss AM/PM")))))))

Number of Hours Between Two Dates Not Working in Excel

As requested, I have included a simplified screenshot that illustrates the issue.
As you can see, I subtracted the two dates and formatted it as "h:mm:ss". Why doesn't this give you the total amount of hours that have passed between the two dates? Is there a better way to do this? There is a great answer below, but I am trying to figure out why doing the way illustrated in this screenshot doesn't work.
END OF EDIT
I am aware that similar questions have been answered here, but for whatever reason this is not working for me at all.
I have two columns: one is a date, one is the time.
As you can see from the currently highlighted cell, the "time" column is actually stored as date with the time included. In column H, I have the date stored as a serial code so that the decimal number refers to a month, day, year, hour, minute, and second. When I subtract the serial code that refers to 2/16/2016 3:20:01 PM from the serial code that refers to refers to 2/14/2016 1:20:01 PM and format that cell as "h:mm", I am getting 2:00. Why?????
I have been hacking away at this for a while and this is supposed to be stupid easy and it's not working. Any help is greatly appreciated so I can move on to more important things.
It does work. Just take the difference between the two dates, format the cell containing the difference as Number, and then use one of the following formulas to get the units you want. I will assume that:
A1 has the value 2/16/2016 3:20:01 PM
B1 has the value 2/14/2016 1:20:01 PM
Into C1 enter A1 - B1, and format it as Number
If you want the difference as days, leave C1 as is.
If you want hours, use =24*(A1 - B1)
If you want minutes, use =24*60*(A1 - B1)
If you want seconds, use =24*60*60*(A1 - B1)
THE ANSWER TO THIS IS REALLY SILLY.
Below, you will find that Tim Biegeleisen provided an excellent answer to this question. I just wanted to further elaborate.
Sometimes having too many option for formatting can be a problem, which is what happened here.
When you subtract 2/14/2016 1:20:01 PM from 2/16/2016 3:20:01 PM and format it as h:mm:ss it only subtracts the hours portion and ignores days. You just have to somehow know that if you are trying to do what I'm trying to do, you have to format it as [h]:mm:ss and then it will calculate the total number of hours passed. The bracket around the "h" is the important part here. I hope this helps the next person who comes across this.

Excel 2010 - calculating time lapsed between 2 dates & times where it is over 31 days

I am trying to find out the time lapsed, Days, Hours & Mins, between 2 days and times?
Date Opened: Cell J1 08/08/2012 09:00:02
Date Resolved: Cell L1 10/10/2012 07:30:00
I have tried the Following:
=INT(L1-J1) &" days "&INT(MOD(L1-J1,1)*24)&" hours " & ROUND(MOD((L1-J1)*24,1)*60,0)&" minutes"
this works and gives the lapsed time of 62 days 22 hours 30 minutes
The problem with this is that produces this as a text result meaning that I cannot Average the results automatically
I then tried:
=L1-J1
The result of this is good as it allows me to use the results and work out averages & sums
But if the lapsed time is over a month it cannot work this out - so this example gives me the incorrect result of 02:22:29 (DD:HH:MM)
What i am looking for is a formula / function that will provide me with the time lapsed in Days/ hours/ mins that correctly shows the number of days even if more than 1 month and that i am able to use the results
thanks
It is a formatting issue. The format of DD:HH:MM is treating the result as a date (2-Mar-1900 22:29)
Unfortunately I don't think there is a built in format which will give total number of days
You can get the text you want by using formula =INT(L1-J1)&":"&TEXT(L1-J1,"HH:MM")but this will be a text value rather than a numerical value
Formatting it to [h]:mm:ss would give you the number of hours. Does that help in anyway?
It seems like this is something that can't be done in one cell, but would need to be handled in 2 cells. 1 for calculating the average (and can be hidden), and one for the display you are looking for.

Elapsed Days Hours Minutes Excluding Weekends and Holidays Time

This sounds simple but I have been pulling my hair out trying to figure out a solution. Any help before I go bald would be great.
I need a formula which is able to
calculate the duration in (days, hrs, mins) between two date\time values (eg 05/12/2012 5:30 PM and say 07/12/2012 5:45 PM);
excluding weekends and holidays.
I would like the result of the formula to read as follows "e.g 2 Days 0 Hrs and 15 Mins".
Thanks
Link to sample workbook
You can use NETWORKDAYS and NETWORKDAYS.INTL to achieve this
A bit of manipulation is required as these return net whole days:
Use these functions to calculate the number of non workdays, then subtract from the difference between start and end dates
=E3-D3-(NETWORKDAYS.INTL(D3,E3,"0000000")-NETWORKDAYS(D3,E3,$A$16:$A$24))
This returns the working day difference, where 1.0 = 1 day
NETWORKDAYS.INTL(D3,E3,"0000000") calculates whole days between the two dates (no weekends, no holidays)
NETWORKDAYS(D3,E3,"0000000",$A$16:$A$24) calculates whole working days days between the two dates (Sat/Sun weekends, holidays as per your list in $A$16:$A$24)
Difference in non-working days between the two dates.
E3-D3 is time between start and end date/times (1.0 = 1 day)
Use custom number formatting to display thye result in the format you require
d "Days" h "Hours" mm "Mins"
Note: this format won't work for negative values, you will need an alternative for when end date is before start date.
The following formula works like a treat with no additional formatting or manipulation.
To make it more stable I have turned all the holiday dates for UK 2012/13 into ‘Excel Serial Number’ format and placed them in an array bracket.
Replacing the "D5" in the formula with your cell reference for your course or metric "End Date" and "E5" with your course or Metric for "Completion Date".
=IF(E5<D5,"-"&TEXT(D5-E5,"h:mm"),NETWORKDAYS(D5,E5,({40910,41005,41008,41036,41064,41065,41148,41268,41269,41275,41362,41365,41400,41421,41512,41633,41634}))-1-(MOD(E5,1)<MOD(D5,1))&" days "&TEXT(E5-D5,"h:mm"))

What is wrong with this calculated field for total hours between two times in SharePoint 2007?

I am attempting to get the total hours between two times in a SharePoint 2007 list. Right now I have the formula as...
=INT(([Column2]-[Column1])*24)
...which I have looked up and says that it is the correct formula to do this. But, what I get is a weird date like "2/18/1900 12:00 AM" instead of what it should be: 26.
Another formula I tried was...
=TEXT([Column2]-[Column1],"h")
...but, this will only get the difference in hours and not count the days (if they are more than one apart).
Both of the columns are Date & Time columns. So, what am I doing wrong?
My take is that you set the output format of the calculated column to be Date and Time, while it should be of type number.
In a calculated column, the number of hours between two times is:
=TEXT([Column2]-[Column1],"h")
Providing that the difference is less than 24 hours. Otherwise, you'll need to look at getting the days difference and doing a multi-step calculation involving the number of days between the dates * 24 + the calc above.

Resources