Check if a time range falls within a range

i have a question

New Member
Joined
Oct 27, 2021
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hey all,

i have a complicated question.

I need to calculate an employees pay based on the time they have worked.
Basically, the employee is paid a meal allowance if they work during a said period of time.

07:30-08:30(breakfast)=25$
12:30-13:30(lunch)=25$
19:30-20:30(dinner)=25$
23:59>(overnight)=15$

the employees starts to work at 14:00 and ends work at 00:15 the next day. So during this time the employee is entitled for a lunch,dinner and overnight. I need a formula to add these values if the employee worked between the start to the end time.

thanks a lot in advance
 

Attachments

  • temp.jpg
    temp.jpg
    48.7 KB · Views: 22

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
MrExcelPlayground4.xlsx
ABC
37:30 AM8:30 AM$ 25.00
412:30 PM1:30 PM$ 25.00
57:30 PM8:30 PM$ 25.00
611:59 PM$ 15.00
7
8Start TimeEnd Time
92:00 PM12:15 AM$ 40.00
107:00 AM4:00 PM$ 50.00
118:00 AM5:00 PM$ 25.00
129:00 AM6:00 PM$ 25.00
1310:00 AM7:00 PM$ 25.00
1411:00 AM8:00 PM$ 25.00
1512:00 PM9:00 PM$ 50.00
161:00 PM10:00 PM$ 25.00
172:00 PM11:00 PM$ 25.00
183:00 PM12:00 AM$ 40.00
Sheet25
Cell Formulas
RangeFormula
C9:C18C9=IF(AND(A9<=$A$3,IF(B9<A9,B9+1,B9)>=$B$3),$C$3,0)+IF(AND(A9<=$A$4,IF(B9<A9,B9+1,B9)>=$B$4),$C$4,0)+IF(AND(A9<=$A$5,IF(B9<A9,B9+1,B9)>=$B$5),$C$5,0)+IF(AND(A9<=$A$6,IF(B9<A9,B9+1,B9)>=$A$6),$C$6,0)
A11:B18A11=A10+1/24
 
Upvote 0
MrExcelPlayground4.xlsx
ABC
37:30 AM8:30 AM$ 25.00
412:30 PM1:30 PM$ 25.00
57:30 PM8:30 PM$ 25.00
611:59 PM$ 15.00
7
8Start TimeEnd Time
92:00 PM12:15 AM$ 40.00
107:00 AM4:00 PM$ 50.00
118:00 AM5:00 PM$ 25.00
129:00 AM6:00 PM$ 25.00
1310:00 AM7:00 PM$ 25.00
1411:00 AM8:00 PM$ 25.00
1512:00 PM9:00 PM$ 50.00
161:00 PM10:00 PM$ 25.00
172:00 PM11:00 PM$ 25.00
183:00 PM12:00 AM$ 40.00
Sheet25
Cell Formulas
RangeFormula
C9:C18C9=IF(AND(A9<=$A$3,IF(B9<A9,B9+1,B9)>=$B$3),$C$3,0)+IF(AND(A9<=$A$4,IF(B9<A9,B9+1,B9)>=$B$4),$C$4,0)+IF(AND(A9<=$A$5,IF(B9<A9,B9+1,B9)>=$B$5),$C$5,0)+IF(AND(A9<=$A$6,IF(B9<A9,B9+1,B9)>=$A$6),$C$6,0)
A11:B18A11=A10+1/24
wow this looks amazing! does it work with 24hour clock format as well?

something i forgot to mention was that my start and end time cell has a date in it as well(30/09/21 21:49) and the clock format is 24hours
 
Upvote 0
The format of the time doesn't matter at all. If the date is in with the time, so much the better. You can actually simplify it because of that.

The IF(B9<A9,B9+1,B9) part tries to account for having no date associated with it. It could just be replaced by "B9" only whereever it appears.
 
Upvote 0
The format of the time doesn't matter at all. If the date is in with the time, so much the better. You can actually simplify it because of that.

The IF(B9<A9,B9+1,B9) part tries to account for having no date associated with it. It could just be replaced by "B9" only whereever it appears.
is it possible for me to PM you my sheet? have some sensitive info on it i'd rather not post.
I used the formula but for whatever reason it's returning the false value?
 
Upvote 0
I can't get strange sheets here...

I'd get the xl2bb add in for this site - and then put up a stripped version. Or just post the formula that you are actually using from one cell.
 
Upvote 0
Basically this is what my table looks like. The first image is where i base my start and end time(check-in checkout)
Image 2 where where i want my pay in $ to appear for each rows checkin and checkout time
image 3 is where i have my allowance pay and time range mentioned
 

Attachments

  • temp.jpg
    temp.jpg
    98 KB · Views: 15
  • temp2.jpg
    temp2.jpg
    70.3 KB · Views: 18
  • temp3.jpg
    temp3.jpg
    24.7 KB · Views: 20
Upvote 0
I think...
Use my original formula, and instead of using the plain reference to the date-time cell - say (B2), "MOD(B2,1)"
 
Upvote 0
I think...
Use my original formula, and instead of using the plain reference to the date-time cell - say (B2), "MOD(B2,1)"
I'm sorry to be a pain, do you mean =IF(AND(MOD(Sheet3!B2,1)<=Sheet2!$J$2,MOD(Sheet3!G2,1)>=Sheet2!$K$2),Sheet2!$I$2,0)+IF(AND(Sheet3!B2<=Sheet2!$J$3,Sheet3!G2>=Sheet2!$K$3),Sheet2!$I$3,0)+IF(AND(Sheet3!B2<=Sheet2!$J$4,Sheet3!G2>=Sheet2!$K$4),Sheet2!$I$4,0)+IF(AND(Sheet3!B2<=Sheet2!$J$5,Sheet3!G2>=Sheet2!$J$5),Sheet2!$I$5,0)

like the bold part? i didnt edit the entire thing as i want to be sure
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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