How to determine whether its a day/night shift from date-time

1260
3
10-16-2017 12:05 AM
by
New Contributor III

Hi,

I'm capturing the date-time(decimal-date-time(now())) for a survey and want to use this to determine whether this falls in the day or night shift. The day shift would be 6am-6pm and night shift 6pm-6am.

I'm thinking I'll need to capture the time, format it and then do an if statement. I'm not sure of the best time format to use along with the appropriate if statement. I have attached an extract of the form of what I have so far.

Many thanks

Tags (4)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

Hi Katherine,

Your Day/Night formula needed a couple of little tweaks:

- The shift_time question calculation should be: format-date(\${shift_date_time},'%H%M')

- The shift question calculation should be: if(\${shift_time} >=600 and \${shift_time} <=1800,'Day','Night')

With calculate questions, it's sometimes helpful to temporarily make them a text question so you can see the output - that's how I spotted the first item.

3 Replies
Esri Esteemed Contributor

Hi Katherine,

Your Day/Night formula needed a couple of little tweaks:

- The shift_time question calculation should be: format-date(\${shift_date_time},'%H%M')

- The shift question calculation should be: if(\${shift_time} >=600 and \${shift_time} <=1800,'Day','Night')

With calculate questions, it's sometimes helpful to temporarily make them a text question so you can see the output - that's how I spotted the first item.

by
New Contributor III

Brilliant, thank you James. Good to know I wasn't too far off and that's a good tip, thank you.

New Contributor

James, Any idea on how you would accomplish this for a 24hr shift? I'm trying to bust out some time frames based on a Fire Department Shift Schedule. The Schedules runs from 7am to 7am.

Thanks