Ranges of dates

Discussion in 'ASP General' started by arbpen, Apr 10, 2007.

  1. arbpen

    arbpen Guest

    I'm sure there's a simple way to do this, but I can't seem to find it:

    If today is after February 1st and before February 15th then
    do valentines
    elseif today is after March 1st and before March 17th then
    do stpatty's day
    elseif today is April 1st then
    do April Fool
    elseif today is after April 15th and before May 5th then
    do CincodeMayo
    else
    just do the regular thing
    end if


    I know about date() and I know about datepart and I know about
    month(date()) and day(date()). Right now
    I do:

    if month(date()) = 2 and day(date()) => 1 and day(date()) < 15 then
    'do valentines
    elseif month(date()) = 3 and day(date()) < 18 then
    'do st pattys
    elseif month(date()) = 4 and day(date()) = 1 then
    'do April fool
    'then I get confused about the best way to do Cinco De Mayo
    else
    'do the regular thing
    end if

    Is there an easier/better way to do this? Thanks in advance for any
    tips, solutions, etc.

    --
    Adrienne Boswell at work
    Administrator nextBlock.com
    http://atlas.nextblock.com/files/
    Please respond to the group so others can share
     
    arbpen, Apr 10, 2007
    #1
    1. Advertising

  2. arbpen

    Evertjan. Guest

    arbpen wrote on 10 apr 2007 in microsoft.public.inetserver.asp.general:

    > I'm sure there's a simple way to do this, but I can't seem to find it:
    >
    > If today is after February 1st and before February 15th then
    > do valentines
    > elseif today is after March 1st and before March 17th then
    > do stpatty's day
    > elseif today is April 1st then
    > do April Fool
    > elseif today is after April 15th and before May 5th then
    > do CincodeMayo
    > else
    > just do the regular thing
    > end if
    >
    >
    > I know about date() and I know about datepart and I know about
    > month(date()) and day(date()). Right now
    > I do:
    >
    > if month(date()) = 2 and day(date()) => 1 and day(date()) < 15 then
    > 'do valentines
    > elseif month(date()) = 3 and day(date()) < 18 then
    > 'do st pattys
    > elseif month(date()) = 4 and day(date()) = 1 then
    > 'do April fool
    > 'then I get confused about the best way to do Cinco De Mayo
    > else
    > 'do the regular thing
    > end if
    >
    > Is there an easier/better way to do this? Thanks in advance for any
    > tips, solutions, etc.



    A sort of practical example from a page of mine:

    <%
    nu = now 'perhaps do a zone change here

    if nu<#2007/04/11 00:00# then
    tx = "blah"
    elseif nu>#2007/05/20 17:00# and nu<#2007/05/23 21:20# then
    tx = "blah blah"
    elseif nu>#2007/06/06 08:15# and nu<#2007/06/10 23:00# then
    tx = "blah blah blah"
    else
    tx = "blah blah blah blip"
    end if
    response.write tx
    %>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 10, 2007
    #2
    1. Advertising

  3. Evertjan. wote:
    > arbpen wrote on 10 apr 2007 in microsoft.public.inetserver.asp.general:
    >
    > > I'm sure there's a simple way to do this, but I can't seem to find it:
    > >
    > > If today is after February 1st and before February 15th then
    > > do valentines
    > > elseif today is after March 1st and before March 17th then
    > > do stpatty's day
    > > elseif today is April 1st then
    > > do April Fool
    > > elseif today is after April 15th and before May 5th then
    > > do CincodeMayo
    > > else
    > > just do the regular thing
    > > end if
    > >
    > >
    > > I know about date() and I know about datepart and I know about
    > > month(date()) and day(date()). Right now
    > > I do:
    > >
    > > if month(date()) = 2 and day(date()) => 1 and day(date()) < 15 then
    > > 'do valentines
    > > elseif month(date()) = 3 and day(date()) < 18 then
    > > 'do st pattys
    > > elseif month(date()) = 4 and day(date()) = 1 then
    > > 'do April fool
    > > 'then I get confused about the best way to do Cinco De Mayo
    > > else
    > > 'do the regular thing
    > > end if
    > >
    > > Is there an easier/better way to do this? Thanks in advance for any
    > > tips, solutions, etc.

    >
    >
    > A sort of practical example from a page of mine:
    >
    > <%
    > nu = now 'perhaps do a zone change here
    >
    > if nu<#2007/04/11 00:00# then
    > tx = "blah"
    > elseif nu>#2007/05/20 17:00# and nu<#2007/05/23 21:20# then
    > tx = "blah blah"
    > elseif nu>#2007/06/06 08:15# and nu<#2007/06/10 23:00# then
    > tx = "blah blah blah"
    > else
    > tx = "blah blah blah blip"
    > end if
    > response.write tx
    > %>
    >


    My hero! :-( But, I need to make this so I _don't_ have to put in the
    year. I need this to be able to sit there as an include until the end
    of time, or the planet blows up, which ever comes first.

    --
    Adrienne Boswell at work
    Administrator nextBlock.com
    http://atlas.nextblock.com/files/
    Please respond to the group so others can share
     
    Adrienne Boswell, Apr 11, 2007
    #3
  4. arbpen wrote:
    > I'm sure there's a simple way to do this, but I can't seem to find it:
    >
    > If today is after February 1st and before February 15th then
    > do valentines
    > elseif today is after March 1st and before March 17th then
    > do stpatty's day
    > elseif today is April 1st then
    > do April Fool
    > elseif today is after April 15th and before May 5th then
    > do CincodeMayo
    > else
    > just do the regular thing
    > end if
    >
    >
    > I know about date() and I know about datepart and I know about
    > month(date()) and day(date()). Right now
    > I do:


    First of all, I would use variables rather than repeatedly calling these
    month and day functions:
    dim mth, dnum
    mth= month(date())
    dnum = day(date())
    >
    > if mth= 2 and dnum=> 1 and dnum< 15 then
    > 'do valentines
    > elseif mth= 3 and dnum< 18 then
    > 'do st pattys
    > elseif mth= 4 and dnum= 1 then
    > 'do April fool
    > 'then I get confused about the best way to do Cinco De Mayo


    elseif (mth= 4 and dnum= 1) or (mth=5 and dnum < 5) then

    >
    > Is there an easier/better way to do this? Thanks in advance for any
    > tips, solutions, etc.


    Can you use a database? A table containing holiday name, startdate and
    enddate would make this pretty easy. Assuming Jet:

    select holiday from holidays where date >= startdate
    and date < enddate

    Just prepopulate the table with several years worth of data. The beauty of
    course is that if new holidays are added or date ranges need to be adjusted,
    there is no need to modify the code, just modify the data in the table.


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Apr 11, 2007
    #4
  5. Gazing into my crystal ball I observed "Bob Barrows [MVP]" <reb01501
    @NOyahoo.SPAMcom> writing in news:#06clA#:

    >>
    >> Is there an easier/better way to do this? Thanks in advance for any
    >> tips, solutions, etc.

    >
    > Can you use a database? A table containing holiday name, startdate and
    > enddate would make this pretty easy.


    I think that's the best solution. I'm already doing that with a Liturgical
    calendar I'm doing for a Catholic church site. Thank you.

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
     
    Adrienne Boswell, Apr 11, 2007
    #5
  6. arbpen

    Evertjan. Guest

    Bob Barrows [MVP] wrote on 11 apr 2007 in
    microsoft.public.inetserver.asp.general:

    > First of all, I would use variables rather than repeatedly calling these
    > month and day functions:
    > dim mth, dnum
    > mth= month(date())
    > dnum = day(date())
    >


    There is the slight possibility of the date change between those two lines,
    so I would do:

    myDate = date()

    mth= month(myDate)
    dnum = day(myDate)


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 11, 2007
    #6
  7. arbpen

    Evertjan. Guest

    Adrienne Boswell wrote on 11 apr 2007 in
    microsoft.public.inetserver.asp.general:

    >> A sort of practical example from a page of mine:
    >>
    >> <%
    >> nu = now 'perhaps do a zone change here
    >>
    >> if nu<#2007/04/11 00:00# then
    >> tx = "blah"
    >> elseif nu>#2007/05/20 17:00# and nu<#2007/05/23 21:20# then

    [...]
    >
    > My hero! :-( But, I need to make this so I _don't_ have to put in the
    > year. I need this to be able to sit there as an include until the end
    > of time, or the planet blows up, which ever comes first.


    What application uses fixed days year in year out,
    independent on the weekday? [except for morgages]

    <% 'vbs
    if weekday(date,7) < 3 then response.write "It's weekend!"
    %>



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 11, 2007
    #7
  8. Evertjan. wrote:
    > Bob Barrows [MVP] wrote on 11 apr 2007 in
    > microsoft.public.inetserver.asp.general:
    >
    >> First of all, I would use variables rather than repeatedly calling
    >> these month and day functions:
    >> dim mth, dnum
    >> mth= month(date())
    >> dnum = day(date())
    >>

    >
    > There is the slight possibility of the date change between those two
    > lines, so I would do:
    >
    > myDate = date()
    >
    > mth= month(myDate)
    > dnum = day(myDate)
    >
    >

    Good point.
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Apr 11, 2007
    #8
    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. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    904
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    231
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    236
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    255
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    188
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page