Calculate Day and Night Shift based on Time

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
Can some one please correct my formula to calculate the Day or Night shift.
07:00 am to 19:00 (Day)
19:00 > to <07:00am (Night)

=IF(AND(C4>=7, C4<=19),"Day","Night")

Thanks
Farhan
1611502302049.png
 

Attachments

  • 1611502270995.png
    1611502270995.png
    26.4 KB · Views: 57

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.
How about
Excel Formula:
=IF(AND(C4>=TIME(7,0,0),C4<=TIME(19,0,0)),"Day","Night")
or
Excel Formula:
=IF(AND(C4*24>=7,C4*24<=19),"Day","Night")
 
Upvote 0
2 more, the simplest one first as you already have the times at the top of the sheet.
Excel Formula:
=IF(AND(C4>=$D$2, C4<=$E$2),"Day","Night")
FYI, times are decimal values, 1 hour is 1/24 days so you were actually looking for 7 and 19 days with your formula instead of hours. Dividing by 24 will covert any integer to hours
Excel Formula:
=IF(AND(C4>=(7/24), C4<=(19/24)),"Day","Night")
or the reverse can be done by multiplying (as in @Fluff's suggestion).
As you can see from the answers provided, there are many ways to convert to time when needed.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
How about
Excel Formula:
=IF(AND(C4>=TIME(7,0,0),C4<=TIME(19,0,0)),"Day","Night")
or
Excel Formula:
=IF(AND(C4*24>=7,C4*24<=19),"Day","Night")
Thanks Fluff it works for me
 
Upvote 0
2 more, the simplest one first as you already have the times at the top of the sheet.
Excel Formula:
=IF(AND(C4>=$D$2, C4<=$E$2),"Day","Night")
FYI, times are decimal values, 1 hour is 1/24 days so you were actually looking for 7 and 19 days with your formula instead of hours. Dividing by 24 will covert any integer to hours
Excel Formula:
=IF(AND(C4>=(7/24), C4<=(19/24)),"Day","Night")
or the reverse can be done by multiplying (as in @Fluff's suggestion).
As you can see from the answers provided, there are many ways to convert to time when needed.
Thanks Jason to explain now I understand why Fluff *24 or can be divide by 24 appreciate put extra effort to explain
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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