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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chumley the Walrus

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

    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
  • dlbjr

    #2
    Re: DatePart function to display date for Monday and Friday of this week

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

    dlbjr
    Pleading sagacious indoctrination!


    Comment

    • Chumley the Walrus

      #3
      Re: DatePart function to display date for Monday and Friday of this week

      "dlbjr" <oops@iforgot.c om> wrote in message news:<eHuFBUuiE HA.384@TK2MSFTN GP10.phx.gbl>.. .[color=blue]
      > Function GetWorkWeekDisp lay()
      > dtmDate = Date
      > intDay = DatePart("w",dt mDate)
      > If intDay < 2 Then
      > dtmMonday = DateAdd("d",1,d tmDate)
      > dtmFriday = DateAdd("d",6,d tmDate)
      > Else
      > dtmMonday = DateAdd("d",-(6-intDay),dtmDate )
      > dtmFriday = DateAdd("d",6-intDay,dtmDate)
      > End If
      > GetWorkWeekDisp lay = dtmMonday & " thru " & dtmFriday
      > End Function
      >
      > dlbjr
      > Pleading sagacious indoctrination![/color]

      Thanks a ton, worked great!

      Comment

      • Chumley the Walrus

        #4
        Re: DatePart function to display date for Monday and Friday of this week

        "dlbjr" <oops@iforgot.c om> wrote in message news:<eHuFBUuiE HA.384@TK2MSFTN GP10.phx.gbl>.. .[color=blue]
        > Function GetWorkWeekDisp lay()
        > dtmDate = Date
        > intDay = DatePart("w",dt mDate)
        > If intDay < 2 Then
        > dtmMonday = DateAdd("d",1,d tmDate)
        > dtmFriday = DateAdd("d",6,d tmDate)
        > Else
        > dtmMonday = DateAdd("d",-(6-intDay),dtmDate )
        > dtmFriday = DateAdd("d",6-intDay,dtmDate)
        > End If
        > GetWorkWeekDisp lay = dtmMonday & " thru " & dtmFriday
        > End Function
        >
        > dlbjr
        > Pleading sagacious indoctrination![/color]

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

        Function GetWorkWeekDisp lay()
        dtmDate = Date
        intDay = DatePart("w",dt mDate)
        If intDay < 2 Then
        dtmMonday = DateAdd("d",1,d tmDate)
        dtmFriday = DateAdd("d",5,d tmDate)
        Elseif intDay = 2 Then
        dtmMonday = DateAdd("d",0,d tmDate)
        dtmFriday = DateAdd("d",4,d tmDate)
        Elseif intDay = 3 Then
        dtmMonday = DateAdd("d",-1,dtmDate)
        dtmFriday = DateAdd("d",3,d tmDate)
        Elseif intDay = 4 Then
        dtmMonday = DateAdd("d",-2,dtmDate)
        dtmFriday = DateAdd("d",2,d tmDate)
        Elseif intDay = 5 Then
        dtmMonday = DateAdd("d",-3,dtmDate)
        dtmFriday = DateAdd("d",1,d tmDate)
        Elseif intDay = 6 Then
        dtmMonday = DateAdd("d",-4,dtmDate)
        dtmFriday = DateAdd("d",0,d tmDate)
        Elseif intDay = 7 Then
        dtmMonday = DateAdd("d",-5,dtmDate)
        dtmFriday = DateAdd("d",-1,dtmDate)
        End If
        GetworkweekDisp lay = dtmMonday & " thru " & dtmFriday
        End Function
        response.write "<font size = 3>" & GetworkweekDisp lay & ""

        Comment

        Working...