ASP - first and last day of each week in a year

Discussion in 'ASP General' started by Charlotte, Jan 4, 2008.

  1. Charlotte

    Charlotte Guest

    Hi,

    is it possible to determine the first and the last day of a week (with
    classic ASP)

    nu = "06/01/2008"
    week = (DatePart("ww",nu))

    firstday = dateadd("d",(-datepart("w",date())),nu)
    lastday = dateadd("d",(7-datepart("w",date())),nu)

    response.write week
    response.write "<br>"
    response.Write firstday
    response.write "<br>"
    response.Write lastday

    'week' must give me the number of the week for the date in 'nu'
    'firstday' must give me the first date of that week
    'lastday' must give me the last date of that week

    it won't work

    is there a way to do this?

    thanks in advance
    Charlotte, Jan 4, 2008
    #1
    1. Advertising

  2. Charlotte

    Evertjan. Guest

    Charlotte wrote on 04 jan 2008 in
    microsoft.public.inetserver.asp.general:

    >
    > Hi,
    >
    > is it possible to determine the first and the last day of a week (with
    > classic ASP)
    >
    > nu = "06/01/2008"


    This is dangerous, did you mean the first of june, nee toch?

    Use:

    nu = #2008/01/06#

    So now nu is a date object and you are sure to have 'overmorgen'.

    > week = (DatePart("ww",nu))


    week = Weekday(nu, 1)

    [1 means sunday is the first day of the week,
    so 1 = sunday, 7 is saturday]

    > firstday = dateadd("d",(-datepart("w",date())),nu)


    firstday = dateadd("d", 1 - week, nu)

    > lastday = dateadd("d",(7-datepart("w",date())),nu)


    lastday = firstday + 6

    > response.write week
    > response.write "<br>"
    > response.Write firstday
    > response.write "<br>"
    > response.Write lastday
    >
    > 'week' must give me the number of the week for the date in 'nu'
    > 'firstday' must give me the first date of that week
    > 'lastday' must give me the last date of that week
    >
    > it won't work


    Never say that in a NG like this,
    show error texts and what you did to debug.

    > is there a way to do this?
    >
    > thanks in advance


    so use this:

    nu = #2008/01/09#
    week = Weekday(nu, 1)
    firstday = dateadd("d", 1 - week, nu)
    lastday = firstday + 6


    Succes,

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 4, 2008
    #2
    1. Advertising

  3. Charlotte

    tim Guest

    Charlotte,

    A lot of information how to work with dates is to be found on the following
    website.
    http://www.chrispearson.org/pages/programming/vbscript/datework/misc/weekday.asp

    Good luck
    Tim

    "Charlotte" <> schreef in bericht
    news:SGffj.10800$-ops.be...
    >
    > Hi,
    >
    > is it possible to determine the first and the last day of a week (with
    > classic ASP)
    >
    > nu = "06/01/2008"
    > week = (DatePart("ww",nu))
    >
    > firstday = dateadd("d",(-datepart("w",date())),nu)
    > lastday = dateadd("d",(7-datepart("w",date())),nu)
    >
    > response.write week
    > response.write "<br>"
    > response.Write firstday
    > response.write "<br>"
    > response.Write lastday
    >
    > 'week' must give me the number of the week for the date in 'nu'
    > 'firstday' must give me the first date of that week
    > 'lastday' must give me the last date of that week
    >
    > it won't work
    >
    > is there a way to do this?
    >
    > thanks in advance
    >
    tim, Jan 8, 2008
    #3
    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. Guest
    Replies:
    3
    Views:
    1,840
    Alexandre
    Dec 22, 2003
  2. Otuatail

    Week of year to full Year

    Otuatail, Dec 8, 2003, in forum: HTML
    Replies:
    4
    Views:
    963
    Toby A Inkster
    Dec 8, 2003
  3. Guest
    Replies:
    3
    Views:
    522
    Alexandre
    Dec 22, 2003
  4. Guest
    Replies:
    3
    Views:
    1,091
    Alexandre
    Dec 22, 2003
  5. SimonC
    Replies:
    13
    Views:
    334
    Dr John Stockton
    Jan 4, 2005
Loading...

Share This Page