time interval within 12hrs

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
444
Office Version
  1. 2019
Hi All, how can i calculate below time interval which is less than 12hrs from 2 cells, is it possible to use in conditional formatting?
11:30 - 22:0008:00 - 17:30wrong
10:00 - 19:3011:30 - 21:00correct
thanks so much
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
VBA Code:
=IF(((RIGHT(B1,5)-LEFT(A1,5))*24)<12,"less than 12hr","")

i've tried this in C1, but it doesn't work in C2 :oops:
 
Upvote 0
In what way doesn't it work?
Both sets of data in your op are less then 12hrs, so why is one "wrong" & the other "correct"?
 
Upvote 0
sorry for any confusing.
i want to avoid any 12hrs interval from today's end to next day's start, so that i need to setup a formula to calculate is there any violation between 2 days.
back to my example 1, 22:00 shift end to the next day 08:00 start which is wrong as my request 12hrs interval.
ps. example 2 is well done so far, 16hrs interval.

thanks so much, fluff
 
Upvote 0
Ok, how about
=IF(RIGHT(A1,5)+0>LEFT(B1,5)+0.5,"less than 12hr","")
 
Upvote 0
this is GREAT.
may i have 2 more further question?
- if one of the comparison time return from my database is 00:00 - 00:00, can it blank as well? (11:30 - 21:00 vs 00:00 - 00:00)
- if comparison within a week, there is no doubt on any question. however if this sunday comparing with last saturday may caused any incorrect?
to prevent any mistake, what if i use another formula on comparison name first and this if statement on next?
SATURDAYSUNDAY
BEE09:15 - 18:45BEE09:15 - 18:45=IF(RIGHT(B2,5)+0>LEFT(E2,5)+0.5,"less than 12hr","")
BRENDA12:00 - 21:30BILL (NEW STAFF)#VALUE!
BRIANBRENDA08:00 - 18:00#VALUE!
BRIAN13:00 - 21:00#VALUE!

thanks so much, fluff
 
Upvote 0
You can use this to get rid of the errors
=IFERROR(IF(RIGHT(B2,5)+0>LEFT(E2,5)+0.5,"less than 12hr",""),"")

The formula assumes that the second time is the day after the first, so Saturday to Sunday is not a problem, but Saturday to Monday might give the wrong result
 
Upvote 0
i tried "11:30 - 21:30 vs 00:00 - 00:00", comes with "less than 12hr", how can i leave it blank as well as others which is not 12hr interval?
if new staff comes, the formula seems not accurate which caused error?

thanks so much, fluff
 
Upvote 0
How about
=IFERROR(IF(OR(RIGHT(A1,5)+0=0,LEFT(B1,5)+0=0),"",IF(RIGHT(A1,5)+0>LEFT(B1,5)+0.5,"less than 12hr","")),"")
 
Upvote 0
How about
=IFERROR(IF(OR(RIGHT(A1,5)+0=0,LEFT(B1,5)+0=0),"",IF(RIGHT(A1,5)+0>LEFT(B1,5)+0.5,"less than 12hr","")),"")

works great, thanks fluff:p
how about enhance the accuracy when new staff comes and avoid any error?
 
Upvote 0

Forum statistics

Threads
1,214,986
Messages
6,122,611
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top