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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    839
    Matthew Speed
    Nov 8, 2003
  2. =?Utf-8?B?QWFyYW43Ng==?=

    datepart function

    =?Utf-8?B?QWFyYW43Ng==?=, Nov 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,975
    Bruce Barker
    Nov 3, 2005
  3. sunspot
    Replies:
    4
    Views:
    14,118
    sunspot
    May 19, 2005
  4. Matt
    Replies:
    2
    Views:
    755
    Pete Becker
    Nov 8, 2003
  5. Matt
    Replies:
    3
    Views:
    937
    Richard Heathfield
    Nov 8, 2003
  6. Matt
    Replies:
    11
    Views:
    648
    Aaron Bertrand [MVP]
    Nov 8, 2003
  7. michaaal
    Replies:
    4
    Views:
    187
    michaaal
    Oct 4, 2004
  8. Daniel Liebig

    find monday of first week of the month

    Daniel Liebig, Jan 22, 2007, in forum: Ruby
    Replies:
    7
    Views:
    371
    Daniel Berger
    Jan 23, 2007
Loading...