Difference between date and time w/out work week Excel - excel

I am trying to determine the amount of time a procedure takes. I have the Start Date and Start Time as well as End Date and End Time. What I need to do is display the result in hours:minutes:seconds BUT I need to use a 7 day work week rather than a 5 day work week. Here is a sample data point:
Cell A1 and C1 are both formatted as short dates. Cell B1 and D1 are formatted as times. The formula in E1 is =((C1+D1)-(A1+B1)) and E1 is formatted as a custom number [h]:mm:ss . The problem I am having is calculating through a weekend. The times just don't add up and I think it is because of the type of work week that Excel uses.
Any help is appreciated, thanks!

First, you need to know / understand that any number is a potential date / time for Excel and that Excel knows only datetime (and not date and time separately).
Here is why: anything before the decimals-placeholder are the days since December 31, 1899. So, the number 42,000.00 is also a date. It is the 42.000th day after December 31, 1899 which is December 27, 2014.
Anything after the decimal-placeholder is considered a fraction of a day. So, the value 0.5 is half a day and therefore the time 12 noon while 0.75 is 6 in the afternoon (pm).
Hence, all of the dates you are showing in your above examples may have also times associated with them and all the times you are showing might also have a date associated to them. Just change the number format on all of these cells to general numbers and you should see only Integer values for the dates (without any decimal places) while all the times should contain only be a fraction of 1 and should all have a 0 before the decimal-placeholder.
If that is not the case, then you have just found your culprit.
With the above knowledge it is also easy to calculate the difference between two dates or times. The difference is a simple addition or subtraction: 42,000.00 + 100 + 0.5 = 100 days after December 27, 2014 at 12 noon = April 6th, 2015 # noon. So, you can just add the numbers and subtract them as you have done. If you wish to subtract two days to account for a weekend then you can simple subtract 2.
Now, let's have a look at your above example:
June 23, 2016 converts to 42,544 while 07:41 in the morning converts to 0.32. So, we have here 42,544.32 while the ending datetime converts to 42,545.47.
The difference is calculated correctly as 1.15. That means that there is a difference of one day and the fraction of a day of 0.15 * 24 (hours in a day) = 3 hours and 36 minutes.
I guess the real problem you are having is to show the result correctly. If you show it as a date then it is one day after December 31, 1899 = January 1st, 1900. If you show the result as a time then you only get to see the 03:36:00. The best is probably to show the difference as a number only as 1.15. If you want to see the result differently then you will have to adjust the resulting view to your needs. For example:
= 1.15 * 24 = 27.6 hours difference between the start date/time and the end date/time.
Let me know if you have any further questions.

Related

Compare two week numbers from different years in Excel

I have some calculations that are strongly dependent on "this week", "next week", etc.
Let's say I have a date (Column A). I can use WEEKNUM((A1), 2) in Column B to get the week number.
In Column C, I can enter this formula to check if the event is this week or next week.
=IF(B1=WEEKNUM((TODAY()),2),"this week",IF(B1=WEEKNUM((TODAY()+7),2),"next week","way in the future"))
This all works great until I have events that cross into next year. So December 31, 2019, will be week 53 and December 31, 2020, will be week 53.
This is an issue because I need a way to account that December 31, 2020 happens later than December 31, 2019.
How do I account for change in years in this formula?
Update:
Adding YEAR as an additional condition will allow me to compare if the date HAS a different year but it still won't let me dynamically calculate, this week, next week.
In this second example, I set two dates and set my computer time as December 31 2019. The result is that instead of reporting 1/1/2020 as "next week" the formula returns "way in the future" which is incorrect.
Is there basically a way to subtract or add weeks using serial week number since epoch time?
Eh, I think I figured it out. Instead of comparing week numbers, we extract the Monday of each week and perform a similar comparison like before. Except we now have the entire date instead of just the week number.
=IF(A2-MOD(A2-2,7)=TODAY()-MOD(TODAY()-2,7),"this week",IF(A2-MOD(A2-2,7)=TODAY()-MOD(TODAY()-2,7)+7,"next week","way in the future"))

Formula to get the worked hours from time A to time B where B is past midnight

I'm using Excel to write down my shifts and get a total of worked hours per day and per week.
I structured it this way:
Everything seemed to work fine until I finished to work at 12.30 am. The result with my formula was -17 hours instead of 7. How can I fix my formula so that it displays a correct amount? I'm using the following formula and I want the result to be displayed in number format, not time.
=IF(C11=0,0,IFERROR(((C11-B11)-D11)*24,0))
What formula can I use?
Excel treats days as 1 for every day past Dec 31, 1899. Today happens to be 42,217. Time is nothing more than a decimal portion of a day. Today at noon was 42,217.5 and tomorrow at 03:00 will be 42,218.125.
Excel also treats boolean (e.g. TRUE/FALSE) values as either 1 or 0 when used in a mathematical equation. e.g. 0.5 + TRUE = 1.5 while 0.5 + FALSE = 0.5.
Test to see if the minuend is less than the subtrahend and if it is, add 1 to it using the result of the test itself.
=(C11+(C11<B11)-B11)*24
      
Finally, it should be mentioned that while you can subtract a larger time from a smaller time to receive a negative decimal value, the negative value cannot be interpreted as time since Excel does not recognize negative time. If you were not multiplying by 24 to retrieve the hours as integers and simply subtracting B11 from C11 the cell would be filled with hashmarks (e.g. ############) to show the error. e.g. 08:00 - 10:00 = (as time) #######.

How do I use the "If" function with hh:mm?

I am trying to use the IF function with the hh:mm format. The objective is to reduce a calculated time by 30 mins IF the total time is equal to or over 9 hours.
Here is the formula I was trying to use, but it doesn't work:
IF(time(hour(T3),minute(t3)<=9, -0,TIME(HOUR(T3), MINUTE(T3) - 30, SECOND(T3))).
Any suggestions would be appreciated.
Thank You.
Date values in Excel are in fact numeric - to put it short it's number of days since January 1, 1900. I.e. 41948.5 means 05 November, 2014 12:00. So one hour equals to 1/24=0.041666.... In your case:
=IF(MOD(T3,1)>=9/24,T3-0.5/24,T3)

Calculate number of specific days in range

How can I count the (fractional) count of specific day of the week in a range? For instance, if the range is from Monday, June 3 12:00 P.M. to Tuesday June 4 12:00 P.M., and I want to count the number of Mondays, the formula would return the result 0.5.
I've already found a formula for the integer number of days:
=SUM(INT((WEEKDAY($B2-x)+$D2-$B2)/7))
where x is the day of the week of interest (1 to 7). Of course, it would need to be modified to return the aforementioned result. How would I do so?
You can get the total number of Mondays (including both start and end date) with this version (you don't need SUM)
=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)
...and then do an adjustment to take into account the start/end days, e.g.
=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)-IF(WEEKDAY($D2)=2,1-MOD($D2,1))-IF(WEEKDAY($B2)=2,MOD($B2,1))
I don't really recommend it (it's much more resource-hungry) but this version should give you the same result
=SUMPRODUCT((TEXT(B2+(ROW(INDIRECT("1:"&ROUND((D2-B2)*1440,0)))-0.5)/1440,"ddd")="mon")+0)/1440
It tests every minute within the date range to ascertain whether or not it falls on a Monday (assumes that you don't go down to seconds)

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"))

Resources