Velocity Reviews > DatePart

# DatePart

le0
Guest
Posts: n/a

 08-11-2006
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
%>

le0
Guest
Posts: n/a

 08-11-2006
Thanks Dave youre d'best =)

"Dave Anderson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> le0 wrote:
>> 'Shift: 10p-6a
>> if DatePart("h", Now()) > 21 And DatePart("h", Now()) < 6 then
>> ShiftID = "C"
>> end if

>
> 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)+1\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.
>