DatePart function to display date for Monday and Friday of this week

Discussion in 'ASP General' started by Chumley the Walrus, Aug 25, 2004.

  1. I'm trying to use DatePart and Datediff functions to show the
    formatted m/dd/yyyy display for the dates of Monday and Friday of the
    current week. I want it to display as:

    Our Weekly Schedule 8/23/2004 thru 8/27/2004:

    Can't pinpoint the parameter to check for the current week. Is there a
    good reference anywhere to show how to use the methods and such of
    both datepart and datediff, or has anyone programmed something similar
    prior.
    Thanks in advance
    Chum
    Chumley the Walrus, Aug 25, 2004
    #1
    1. Advertising

  2. Chumley the Walrus

    dlbjr Guest

    Function GetWorkWeekDisplay()
    dtmDate = Date
    intDay = DatePart("w",dtmDate)
    If intDay < 2 Then
    dtmMonday = DateAdd("d",1,dtmDate)
    dtmFriday = DateAdd("d",6,dtmDate)
    Else
    dtmMonday = DateAdd("d",-(6-intDay),dtmDate)
    dtmFriday = DateAdd("d",6-intDay,dtmDate)
    End If
    GetWorkWeekDisplay = dtmMonday & " thru " & dtmFriday
    End Function

    dlbjr
    Pleading sagacious indoctrination!
    dlbjr, Aug 25, 2004
    #2
    1. Advertising

  3. "dlbjr" <> wrote in message news:<>...
    > Function GetWorkWeekDisplay()
    > dtmDate = Date
    > intDay = DatePart("w",dtmDate)
    > If intDay < 2 Then
    > dtmMonday = DateAdd("d",1,dtmDate)
    > dtmFriday = DateAdd("d",6,dtmDate)
    > Else
    > dtmMonday = DateAdd("d",-(6-intDay),dtmDate)
    > dtmFriday = DateAdd("d",6-intDay,dtmDate)
    > End If
    > GetWorkWeekDisplay = dtmMonday & " thru " & dtmFriday
    > End Function
    >
    > dlbjr
    > Pleading sagacious indoctrination!


    Thanks a ton, worked great!
    Chumley the Walrus, Aug 26, 2004
    #3
  4. "dlbjr" <> wrote in message news:<>...
    > Function GetWorkWeekDisplay()
    > dtmDate = Date
    > intDay = DatePart("w",dtmDate)
    > If intDay < 2 Then
    > dtmMonday = DateAdd("d",1,dtmDate)
    > dtmFriday = DateAdd("d",6,dtmDate)
    > Else
    > dtmMonday = DateAdd("d",-(6-intDay),dtmDate)
    > dtmFriday = DateAdd("d",6-intDay,dtmDate)
    > End If
    > GetWorkWeekDisplay = dtmMonday & " thru " & dtmFriday
    > End Function
    >
    > dlbjr
    > Pleading sagacious indoctrination!


    I revised the script somewhat to make sure it always displays monday's
    and friday's correct date for the current week:

    Function GetWorkWeekDisplay()
    dtmDate = Date
    intDay = DatePart("w",dtmDate)
    If intDay < 2 Then
    dtmMonday = DateAdd("d",1,dtmDate)
    dtmFriday = DateAdd("d",5,dtmDate)
    Elseif intDay = 2 Then
    dtmMonday = DateAdd("d",0,dtmDate)
    dtmFriday = DateAdd("d",4,dtmDate)
    Elseif intDay = 3 Then
    dtmMonday = DateAdd("d",-1,dtmDate)
    dtmFriday = DateAdd("d",3,dtmDate)
    Elseif intDay = 4 Then
    dtmMonday = DateAdd("d",-2,dtmDate)
    dtmFriday = DateAdd("d",2,dtmDate)
    Elseif intDay = 5 Then
    dtmMonday = DateAdd("d",-3,dtmDate)
    dtmFriday = DateAdd("d",1,dtmDate)
    Elseif intDay = 6 Then
    dtmMonday = DateAdd("d",-4,dtmDate)
    dtmFriday = DateAdd("d",0,dtmDate)
    Elseif intDay = 7 Then
    dtmMonday = DateAdd("d",-5,dtmDate)
    dtmFriday = DateAdd("d",-1,dtmDate)
    End If
    GetworkweekDisplay = dtmMonday & " thru " & dtmFriday
    End Function
    response.write "<font size = 3>" & GetworkweekDisplay & ""
    Chumley the Walrus, Aug 27, 2004
    #4
    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. Matt
    Replies:
    1
    Views:
    572
    Matthew Speed
    Nov 8, 2003
  2. Matt
    Replies:
    2
    Views:
    494
    Pete Becker
    Nov 8, 2003
  3. Matt
    Replies:
    3
    Views:
    695
    Richard Heathfield
    Nov 8, 2003
  4. Matt
    Replies:
    11
    Views:
    392
    Aaron Bertrand [MVP]
    Nov 8, 2003
  5. michaaal
    Replies:
    4
    Views:
    93
    michaaal
    Oct 4, 2004
Loading...

Share This Page