If statement with Date & time

shonaart

Board Regular
Joined
Nov 1, 2004
Messages
214
Hi
Please could you help

Column A : Date & time ( 23 march 2011 14:35 )

In column B: I want the formula to look at column A and return three possible asnswers.

If the time is between 06:00 to 13:59 = AM shift
If the time is between 14:00 to 21:59 = PM Shift
If the time is between 22:00 to 06:00 = Night Shift.

Remember there is a dat attached to the time. I do not want to split the date & time pls.

Thanks
Vaughan
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Like this?

Excel Workbook
AB
223/03/2011 14:35PM Shift
323/03/2011 19:37PM Shift
424/03/2011 0:39Night Shift
524/03/2011 5:42Night Shift
624/03/2011 10:44AM Shift
724/03/2011 15:47PM Shift
Shift
 
Upvote 0
I think that you could tidy that a little by just having the 3 shift options in the LOOKUP function.

=LOOKUP(MOD(A2+2/24,1),{0,0.3333,0.6667},{"Night","AM","PM"})&" Shift"
 
Upvote 0
"Hi I am trying to work timesheet in any given 7 days period of variable rate Day, Night, Saturday and Sunday rate only have two input example start 22/07/2011 16:00 finish 23/07/2011 04:00 which is 12 hours but night rate kicks in at 18:00 which means in this case 2 hours in day rate and 10 hours in night rate.
Saturday/Sunday rate start and finish 0000 to 2359 I HAVE looked at a few IF/AND statements to separate the different hours from each 24 hour shift to work out hourly rates then add them together to get total but I am faced with brick wall : please help"
 
Upvote 0
Thank you Petter SS for the help with the Formula it works great however would it possible for the formula to distinguish between a weekday and weekend.

Monday to friday there are three shifts ( AM, PM, Night )
Weeekends, Sat & Sun there are two shifts ( AM , Night )

Would it be possible to add this into the formula , it would be a great help thanks.
Vaughan
 
Upvote 0
Thank you Petter SS for the help with the Formula it works great however would it possible for the formula to distinguish between a weekday and weekend.

Monday to friday there are three shifts ( AM, PM, Night )
Weeekends, Sat & Sun there are two shifts ( AM , Night )

Would it be possible to add this into the formula , it would be a great help thanks.
Vaughan
It is quite likely possible. However, to suggest a formula would require us to know more about the changed requirements.

For example, are the 'AM' and 'Night' shift times the same on weekends?

- If so, what do you want returned if a weekend time is outside those shift times?

- If not, tell us more about what happens on weekends.

Some varied weekend sample data and expected results might help clarify.
 
Upvote 0
Hi Peter, thanks for the reply

1. Yes the times are the same every saturday and Sunday, 06H00 to 18H00 ( AM ) and them 18H00 to 06H00 PM shift.
It is also like that on public holidays but you do not have to worry about that as that will get too complex then.

So im summary , they work:

1. Monday to Friday AM = 06H00 to 14H00
PM = 14Hoo to 22H00
Night = 22H00 to 06H00

2. Saturday & Sunday AM = 06H00 t0 18H00
Night = 18H00 to 06H00

Thanks for your help, much appreciated
 
Upvote 0
Building that into a single formula would make it quite a long formula. I suggest setting up some lookup tables and helper cells and then the formula is simpler. It should also cope with public holidays.

Column D contains a list of public holiday dates.
Columns F:I contain the lookup tables for the different types of shifts.

Formulas in B2 and C2 are copied down.

(All of columns C:I could be hidden after they are populated.)

I have just formatted columns A and D to show the day so it was easier for checking.

Excel Workbook
ABCDEFGHIJ
1Date/TimeShiftNormal DayPublic HolidaysShifts
2Wed 23/03/11 14:35PMTRUEMon 28/03/11 0:00NormalW/End or Pub Hol
3Wed 23/03/11 19:37PMTRUEFri 27/05/11 0:00Start TimeShiftStart TimeShift
4Thu 24/03/11 0:39NightTRUE0Night0PM
5Thu 24/03/11 5:42NightTRUE0.25AM0.25AM
6Thu 24/03/11 10:44AMTRUE0.5833PM0.75PM
7Thu 24/03/11 15:47PMTRUE0.9167Night
8Sat 26/03/11 5:42PMFALSE
9Sat 26/03/11 10:44AMFALSE
10Sat 26/03/11 15:47AMFALSE
11Mon 28/03/11 5:42PMFALSE
12Mon 28/03/11 10:44AMFALSE
13Mon 28/03/11 22:47PMFALSE
14Tue 29/03/11 22:47NightTRUE
Shift
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

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