DatePart

L

le0

Hello guys,

Is there anything wrong with my code (see below) bcoz when 10p-6a shift my
browser returns the error cannot be a zero-length string. Im wondering why,
bcoz the 2 other shift works perfectly.

<%
'Shift: 6a-2p
if DatePart("h", Now()) > 5 And DatePart("h", Now()) < 14 then
ShiftID = "A"
end if

'Shift: 2p-10p
if DatePart("h", Now()) > 13 And DatePart("h", Now()) < 22 then
ShiftID = "B"
end if

'Shift: 10p-6a
if DatePart("h", Now()) > 21 And DatePart("h", Now()) < 6 then
ShiftID = "C"
end if
%>
 
L

le0

Thanks Dave youre d'best =)

Dave Anderson said:
When is something greater than 21 AND less than 6? Unlike your other
conditions, you can use OR for this one:

If DatePart("h",Now) > 21 OR DatePart("h",Now) < 6 Then
ShiftID = "C"
End If

Of course, this might not be a bad place for a Select Case Statement:

Select Case DatePart("h",Now)
Case 6,7,8,9,10,11,12,13 ShiftID = "A"
Case 14,15,16,17,18,19,20,21 ShiftID = "B"
Case Else ShiftID = "C"
End Select

And if you really want to shorten it, this will handle all three of your
conditions:

Shifts = Array("A","B","C")
ShiftID = Shifts((DatePart("h",Now)+18)\8 Mod 3)


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top