Hi John,
Thank you very much! I ended up using your formula with just some tiny
modifications and it worked really well. Here's what my formula looked like:
Shift: IIf([On Duty Time] Is Null,Null,Switch(TimeValue([On Duty
Time])<#6:30:00 AM#,"3rd",TimeValue([On Duty Time])<#2:30:00
PM#,"1st",TimeValue([On Duty Time])<#10:30:00 PM#,"2nd",True,"3rd"))
I'm not familiar with the Switch function. Can you answer a couple more
questions for me?
1. What is the purpose of the final "True"?
2. How is the final "3rd" used? Does it mean that if none of the above are
true then by default make it 3rd?
Leslie
"John W. Vinson" wrote:
> On Mon, 20 Apr 2009 19:44:01 -0700, Leslie <(E-Mail Removed)>
> wrote:
>
> >I have a database with "On Duty" dates and times combined in one field, for
> >example "04/20/2009 06:015:00 AM". I am trying to group the time values by
> >shift. The date isn't important. I couldn't figure out how to do this with
> >such a large date so I created a table with TimeValue and now I am trying to
> >compare the times using IIF statements:
> >
> >1st Shift is between 06:30:00 AM and 02:30:00 PM
> >2nd shift is between 02:30:00 PM and 10:30:00 PM
> >3rd shift is between 10:30:00 PM and 06:30:00 AM
> >
> >I have tried writing lots of ways to write this. Here's the latest:
> >Shift: IIf([T_ZZ_2009_Crew_Chart_Data]![On Duty Time]<"02:30:00 PM","1st
> >Shift",IIf([T_ZZ_2009_Crew_Chart_Data]![On Duty Time]<"10:30:00 PM","2nd
> >shift",IIf([T_ZZ_2009_Crew_Chart_Data]![On Duty Time]<"06:30:00 AM","3rd
> >Shift")))
> >
> >What is the best way to do this? Do i need the quotes around the times?
> >Should I use "Between" and if so, how?
> >
> >Thanks,
>
> Well, you certainly do NOT need another table, in fact it would be a big
> hassle to have one!
>
> Instead, I'd use the Switch() function. It takes arguments in pairs, and
> evaluates them left to right; when it first encounters a True value in the
> first member of a pair it returns the second member and quits. So:
>
> Shift: Switch(TimeValue([On Duty]) < #06:30#, "3rd", TimeValue([On Duty]) <
> #14:30#, "1st",TimeValue([On Duty]) < #22:30#, "2nd",True, "3rd")
>
> This notes that as a pure time, the 3rd shift is split into two disjoint
> periods. Date/Time values are stored as a count of days and fractions of a day
> since midnight December 30, 1899; so the third shift is the block at the end
> of that day, from 10:30 to midnight, and also a block at the beginning of the
> day, midnight to 6:30.
> --
>
> John W. Vinson [MVP]
>
|