Greater than equal to Less than with time format formula

waqasgul

New Member
Joined
Jan 26, 2022
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
Hello, I'm trying to create a formula to automatically calculate on the amount of time.

Here's the time I need to input.

trying this but not working as per my required. =IF(F4="IN","",LOOKUP((E4-E3)*24,{0,2,4},{"Short Leave","Half Day","Present"}))

If the difference between IN and OUT time is greater than or equal to 2 Hours but less than 8 hours = "Short Leave", If the difference is greater than or equal to 4 Hours but less than 8 Hours = "Half Day"

Hopefully this isn't too complex to write, thanks in advance!
 

Attachments

  • Capture.JPG
    Capture.JPG
    70.9 KB · Views: 47

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You'll need to get the Logic right first. If, for example, the time difference was 5 hours - it would be True for both conditions:

5 hours is "greater than or equal to 2 Hours but less than 8 hours"

5 hours is "greater than or equal to 4 Hours but less than 8 Hours"
 
Upvote 0
Try this in cell J5: =IF(H5="Present",IF((G5-G4)*24>=8,"Present",IF((G5-G4)*24>=4,"Half Day","Short Leave")))
 
Upvote 0
Another possible solution:
Excel Formula:
=IF(F4="IN","",LOOKUP((E4-E3)*24,{4,6,8},{"Half Day","Short Leave","Present"}))
 
Upvote 0
Try this in cell J5: =IF(H5="Present",IF((G5-G4)*24>=8,"Present",IF((G5-G4)*24>=4,"Half Day","Short Leave")))
Sorry, should have read
Excel Formula:
=IF(H5="Present",IF((E5-E4)*24>=8,"Present",IF((E5-E4)*24>=4,"Half Day","Short Leave")))
 
Upvote 0
Great help both of you, outstanding and Thank you So much for your precious help.

@kevin9999 can you please help once more. how do i change in the formula if the total duty hours are 9. and other will be same, if 2 hour late IN or earlier OUT will be mark Short Leave and 4 hour late IN or 4 hour earlier OUT will be mark Half Day.

Thank You so much.
 
Upvote 0
Another possible solution:
Excel Formula:
=IF(F4="IN","",LOOKUP((E4-E3)*24,{4,6,8},{"Half Day","Short Leave","Present"}))

@shknbk2 in this how can i change as per below. is this possible please?

can you please help once more. how do i change in the formula if the total duty hours are 9. and other will be same, if 2 hour late IN or earlier OUT will be mark Short Leave and 4 hour late IN or 4 hour earlier OUT will be mark Half Day.
 
Upvote 0
Great help both of you, outstanding and Thank you So much for your precious help.

@kevin9999 can you please help once more. how do i change in the formula if the total duty hours are 9. and other will be same, if 2 hour late IN or earlier OUT will be mark Short Leave and 4 hour late IN or 4 hour earlier OUT will be mark Half Day.

Thank You so much.
Try this to start
Rich (BB code):
=IF(H5="Present",IF((E5-E4)*24>=9,"Present",IF((E5-E4)*24>=4,"Half Day","Short Leave")))
 
Upvote 0
Well, for mine, it would be simple to change it to this for the 9-hour days:
Excel Formula:
=IF(F4="IN","",LOOKUP((E4-E3)*24,{4,7,9},{"Half Day","Short Leave","Present"}))

But I wanted to find a formula that wouldn't have to be manually changed. I haven't found that the "7" and "9" values in the array can be cell references. Therefore, rather than using LOOKUP, I searched for another solution.

This one below works based on the cell with "Total Work Hours = 8". The ISNUMBER/SEARCH function returns 1 if the cell contains "9" and returns 0 otherwise. If the total work hours is 8, nothing is subtracted from the time difference (e.g., 8 hours in the fourth day - 8am to 4pm), so the result is "Present". However, if the work day was 9 hours, 1 hour is subtracted so the result is 7 hours, which means that that day is "Short Leave" since the employee left at 4pm rather than 5pm. In the formula, $C$17 is the total work hours cell. Change it if yours ends up being different.

I also changed the {4,6,8} to {0,6,8} since the 4-hour day for SP-07 results in "#N/A" for missing 5 hours in a 9-hour day; however, you can change it back to 4 if you prefer. If you want some other code to indicate working less than 4 hours, you can add another term at the beginning of the "Half Day" array for the 0-4 hour range, for example, and make the first array {0,4,6,8}.

Excel Formula:
=IF(F4="IN","",LOOKUP((E4-E3)*24-(--ISNUMBER(SEARCH("9",$C$17))),{0,6,8},{"Half Day","Short Leave","Present"}))
 
Upvote 0
Solution

Forum statistics

Threads
1,214,653
Messages
6,120,757
Members
448,991
Latest member
Hanakoro

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