DatePart

Discussion in 'ASP General' started by le0, Aug 11, 2006.

  1. le0

    le0 Guest

    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, Aug 11, 2006
    #1
    1. Advertising

  2. le0

    le0 Guest

    Thanks Dave youre d'best =)

    "Dave Anderson" <> wrote in message
    news:...
    > 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)+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.
    >
     
    le0, Aug 11, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWFyYW43Ng==?=

    datepart function

    =?Utf-8?B?QWFyYW43Ng==?=, Nov 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,783
    Bruce Barker
    Nov 3, 2005
  2. David

    DatePart query

    David, Sep 16, 2003, in forum: ASP General
    Replies:
    3
    Views:
    185
    Tom B
    Sep 17, 2003
  3. Tipple
    Replies:
    2
    Views:
    136
    Tipple
    Oct 16, 2003
  4. Chumley the Walrus
    Replies:
    3
    Views:
    145
    Chumley the Walrus
    Aug 27, 2004
Loading...

Share This Page