I'm have a site that will display a banner image based on the time of year.
My date ranges go from:

4/1 - 6/30
7/1 - 9/30
10/1-11/30
12/1 - 3/31

My script is below. The first three ranges work fine, but the last one spans
two different years. If it's 2007, the range will be 12/1/2007 - 3/31/2007.
Obviously, that won't work. And, when the year changes to 2008, none of the
date ranges will be true because the 12/1-3/31 range will now be 12/1/2008 -
3/31/2008.

I thought about incrementing the year for 3/31 based on the current year,
but if the current year is correct, I can't increment it.

Suggestions? Just not sure how to go about this.

Thanks!
Doug

if Date >= CDate("4/1/" & Year(Date)) AND Date <= CDate("6/30/" &
Year(Date)) then
Response.Write "<img src=""/images/display/Banner.jpg"" >"

elseif Date >= CDate("7/1/" & Year(Date)) AND Date <= CDate("9/30/" &
Year(Date)) then
Response.Write "<img src=""/images/display/Banner.jpg"" >"

elseif Date >= CDate("10/1/" & Year(Date)) AND Date <= CDate("11/30/" &
Year(Date)) then
Response.Write "<img src=""/images/display/Banner.jpg"" >"

elseif Date >= CDate("12/1/" & Year(Date)) AND Date <= CDate("3/31/" &
Year(Date)) then
Response.Write "<img src=""/images/display/Banner.jpg"" >"

end if

Re: Date range problem by Richard

Richard
Mon Dec 03 15:16:05 PST 2007

Doug wrote:

> I'm have a site that will display a banner image based on the time of
> year. My date ranges go from:
>
> 4/1 - 6/30
> 7/1 - 9/30
> 10/1-11/30
> 12/1 - 3/31
>
> My script is below. The first three ranges work fine, but the last one
> spans two different years. If it's 2007, the range will be 12/1/2007 -
> 3/31/2007. Obviously, that won't work. And, when the year changes to 2008,
> none of the date ranges will be true because the 12/1-3/31 range will now
> be 12/1/2008 - 3/31/2008.
>
> I thought about incrementing the year for 3/31 based on the current year,
> but if the current year is correct, I can't increment it.
>
> Suggestions? Just not sure how to go about this.
>
> Thanks!
> Doug
>
> if Date >= CDate("4/1/" & Year(Date)) AND Date <= CDate("6/30/" &
> Year(Date)) then
> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>
> elseif Date >= CDate("7/1/" & Year(Date)) AND Date <= CDate("9/30/" &
> Year(Date)) then
> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>
> elseif Date >= CDate("10/1/" & Year(Date)) AND Date <= CDate("11/30/" &
> Year(Date)) then
> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>
> elseif Date >= CDate("12/1/" & Year(Date)) AND Date <= CDate("3/31/" &
> Year(Date)) then
> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>
> end if
>

I would use the Month function and a Select Case statement. For example:

Select Case Month(Date())
Case 4, 5, 6
' Spring.
Case 7, 8, 9
' Summer.
Case 10, 11
' Autumn
Case 12, 1, 2, 3
' Winter
End Select

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Date range problem by Doug

Doug
Mon Dec 03 15:43:06 PST 2007

Thank you! That did the trick. The solution was a lot simplier with select
case.

Doug

"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:u7Jf$JgNIHA.5360@TK2MSFTNGP03.phx.gbl...
> Doug wrote:
>
>> I'm have a site that will display a banner image based on the time of
>> year. My date ranges go from:
>>
>> 4/1 - 6/30
>> 7/1 - 9/30
>> 10/1-11/30
>> 12/1 - 3/31
>>
>> My script is below. The first three ranges work fine, but the last one
>> spans two different years. If it's 2007, the range will be 12/1/2007 -
>> 3/31/2007. Obviously, that won't work. And, when the year changes to
>> 2008, none of the date ranges will be true because the 12/1-3/31 range
>> will now be 12/1/2008 - 3/31/2008.
>>
>> I thought about incrementing the year for 3/31 based on the current year,
>> but if the current year is correct, I can't increment it.
>>
>> Suggestions? Just not sure how to go about this.
>>
>> Thanks!
>> Doug
>>
>> if Date >= CDate("4/1/" & Year(Date)) AND Date <= CDate("6/30/" &
>> Year(Date)) then
>> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>>
>> elseif Date >= CDate("7/1/" & Year(Date)) AND Date <= CDate("9/30/" &
>> Year(Date)) then
>> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>>
>> elseif Date >= CDate("10/1/" & Year(Date)) AND Date <= CDate("11/30/" &
>> Year(Date)) then
>> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>>
>> elseif Date >= CDate("12/1/" & Year(Date)) AND Date <= CDate("3/31/" &
>> Year(Date)) then
>> Response.Write "<img src=""/images/display/Banner.jpg"" >"
>>
>> end if
>>
>
> I would use the Month function and a Select Case statement. For example:
>
> Select Case Month(Date())
> Case 4, 5, 6
> ' Spring.
> Case 7, 8, 9
> ' Summer.
> Case 10, 11
> ' Autumn
> Case 12, 1, 2, 3
> ' Winter
> End Select
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>



Re: Date range problem by Dr

Dr
Tue Dec 04 02:44:37 PST 2007

In microsoft.public.scripting.vbscript message <u7Jf$JgNIHA.5360@TK2MSFT
NGP03.phx.gbl>, Mon, 3 Dec 2007 17:16:05, "Richard Mueller [MVP]"
<rlmueller-nospam@ameritech.nospam.net> posted:
>
>Select Case Month(Date())
> Case 4, 5, 6
> ' Spring.
> Case 7, 8, 9
> ' Summer.
> Case 10, 11
> ' Autumn
> Case 12, 1, 2, 3
> ' Winter
>End Select

And if the requirements should change so that the transitions are on
arbitrary days of their months, the OP can most easily express the
necessary tests by using a pseudo-date :
D = Date() : D = Month(D)*100 + Day(D)
if D>1225 then ' Next Christmas is next year.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.