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

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)

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

Excel - time of year/day/date/time to determine peak/offpeak

I'm looking for a formula in excel that lets me know if a date each date/time is peak or off-peak (electricity use data). Peak/off-peak is determined by the season, day of the week and time.
Peak equals:
JUNE-SEPTEMBER (SUMMER)
- mon, tue, wed thurs, fri and hour 9:00-18:00
OCTOBER-MAY (WINTER)
-mon, tue, wed, thurs, fri and hours 8:00-21:00
Off-peak - All other hours. (ie where this is false)
I have the code to determine if something is off/on peak individually:
June-September
IF(AND(WEEKDAY(A2,2)<=5,WEEKDAY(A2,2)>=1,A2-INT(A2)>=0.375,A2-INT(A2)<=0.75),"peak","off-peak"))
October-May
IF(AND(WEEKDAY(A2,2)<=5,WEEKDAY(A2,2)>=1,A2-INT(A2)>=0.333,A2-INT(A2)<=0.875),"peak","off-peak"))
However, my problem is I don't know how to put these together with a date like
01/02/2019 09:00 to do the first step to determine if it qualifies as SUMMER or WINTER. Would this be workable with a nested IF in excel? I can't seem to get this.
Making a separate column with an If statement that shows if the date is winter or summer is easy, and I've done it. But I still don't know how to combine this with the above functions.
Many thanks.
Excel - day/date/time to determine peak/offpeak
I want the output to just tell me peak or off peak, but the variable hours depending on the time of year is tripping me up.
Yeah nested if statements. If you've got your formula for SUMMER/WINTER in A1, then nest like this:
=IF($A$1="SUMMER",IF(AND(WEEKDAY(A2,2)<=5,WEEKDAY(A2,2)>=1,A2-INT(A2)>=0.375,A2-INT(A2)<=0.75),"peak","off-peak")),IF(AND(WEEKDAY(A2,2)<=5,WEEKDAY(A2,2)>=1,A2-INT(A2)>=0.333,A2-INT(A2)<=0.875),"peak","off-peak")))
The WEEKDAY function is really MOD(<date>, 7) with some adjustments. Using MOD, anything less than 2 is Saturday or Sunday.
The HOUR function quickly converts true time to an integer that can be compared to a set of paramters which are adjusted for summer/winter.
=IF(OR(MOD(A2, 7)<2, HOUR(A2)<(9-ISNA(MATCH(MONTH(A2), {6,7,8,9}, 0))), HOUR(A2)>(18+ISNA(MATCH(MONTH(A2), {6,7,8,9}, 0))*3)), "off-", "")&"peak"

How to conditionaly check an hour difference between two dates in excel

I have a date with hours and minutes like 2/3/2019 10:30 am , and I do the following to find the diffence in hours which I already formatted like ( h )
=now() - date
I want to check if the difference is more than 12 ( where I mean 12 hours) to do something.
if(actual difference>12; "hello"; "bye")
But is not checking the actual difference but the serial difference
How can I check the actual difference in hours?
Dates are stored as numbers where the integer part is the number of days since 1899-12-31. The fractional part measures the time within a day. So, 24 * (now() - date) will give you the number of hours elapsed.
NB: the formatting is only a question of display and won't influence what's done by the formulas.
In order to check conditionaly the difference in the hours unit between two times we can do if(hour(actual difference)>12; "hello"; "bye")
We put the function hour() as noted in
https://support.office.com/en-us/article/calculate-the-difference-between-two-times-e1c78778-749b-49a3-b13e-737715505ff6

Difference between date and time w/out work week 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.

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