1. Senior Member
Join Date
Dec 1969
Posts
115

Hi, I need to check if a given date (date1) is between memorial day and labor day. Here is what I have so far and it will tell me if the current date is either but im not sure what to do from here, im new to working with dates.<BR><BR>&#060;%<BR>date1 = 5/31/2004<BR>Function GetLaborDay(ByVal HolidayYear)<BR><BR>Dim dtOut<BR> dtOut = GetXOccuranceOfWeekdayInMonth(9, HolidayYear, vbMonday, 1)<BR><BR> GetLaborDay = dtOut<BR><BR>End Function<BR><BR>&#039;Memorial Day is the 4th Monday of May:<BR><BR><BR>Function GetMemorialDay(ByVal HolidayYear)<BR><BR>Dim dtOut<BR> dtOut = GetXOccuranceOfWeekdayInMonth(5, HolidayYear, vbMonday, 4)<BR><BR> GetMemorialDay = dtOut<BR><BR>End Function<BR><BR>&#039;The helper function:<BR>Function GetXOccuranceOfWeekdayInMonth(ByVal TheMonth, ByVal TheYear, ByVal TheWeekday, ByVal TheOccurance)<BR><BR>Dim dtOut<BR>Dim dtLoop<BR>Dim iCnt, _<BR> iOccuranceCnt<BR> dtLoop = DateSerial(TheYear, TheMonth, 1)<BR><BR> While IsDate(dtOut) = False And Month(dtLoop) = TheMonth<BR> If Weekday(dtLoop) = TheWeekday Then<BR> iOccuranceCnt = iOccuranceCnt + 1<BR><BR> If iOccuranceCnt = TheOccurance Then<BR> dtOut = dtLoop<BR> End If<BR> End If<BR><BR> dtLoop = DateAdd("d", 1, dtLoop)<BR> Wend<BR><BR> GetXOccuranceOfWeekdayInMonth = dtOut<BR><BR>End Function<BR><BR><BR>if date1 &#062; getmemorialday OR date1 &#060; dtout then<BR>response.write "yes"<BR>End if<BR>%&#062;<BR><BR>Also, thanks God for your help yesterday<BR>George

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## AND, not OR, for starters

Think about it. Today is a day in March, 3rd month. Memorial day is in May, 5th month. Labor day in September, 9th month.<BR><BR>So just using month number and ignoring year and day:<BR><BR> If 3 &#062; 5 OR 3 &#060; 9 Then<BR><BR>Well, 3 is not &#062; 5, but it *IS* &#060; 9. So your logic would be saying "Yep, March must be between May and September."<BR><BR>Whereas:<BR> If 3 &#062; 5 AND 3 &#060; 9 Then<BR>now *both* conditions have to be true, and the logic would say "Nope, March is not between May and September."<BR><BR>Has nothing to do with dates. Just with logic.<BR><BR>********************<BR><BR>Having said all that...<BR><BR>You apparently don&#039;t understand how functions work.<BR><BR>Look at the declaration of the function:<BR> Function GetMemorialDay(ByVal HolidayYear)<BR><BR>You are supposed to GIVE the function the YEAR that you want the memorial day *FOR*. Similarly with labor day.<BR><BR>So:<BR> If date1 &#062;= GetMemorialDay(Year(date1)) AND date1 &#060;= GetLaborDay(Year(date1)) Then<BR> Response.Write "Yes, " & date1 & " is between Memorial and Labor Days, inclusive."<BR> End If<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
115

## RE: Thanks Bill

seems I always try to make things hardert than they really are, and yes im new to functions, thats one thing board is for, right? :) newbies...LOL

4. Senior Member
Join Date
Dec 1969
Posts
115

## RE: Still doesnt work

Still doesnt work....<BR><BR><BR>&#060;%<BR>date1 = 5/31/2004<BR>Function GetLaborDay(ByVal HolidayYear)<BR><BR>Dim dtOut<BR> dtOut = GetXOccuranceOfWeekdayInMonth(9, HolidayYear, vbMonday, 1)<BR><BR> GetLaborDay = dtOut<BR><BR>End Function<BR><BR>&#039;Memorial Day is the 4th Monday of May:<BR><BR><BR>Function GetMemorialDay(ByVal HolidayYear)<BR><BR>Dim dtOut<BR> dtOut = GetXOccuranceOfWeekdayInMonth(5, HolidayYear, vbMonday, 4)<BR><BR> GetMemorialDay = dtOut<BR><BR>End Function<BR><BR>&#039;The helper function:<BR>Function GetXOccuranceOfWeekdayInMonth(ByVal TheMonth, ByVal TheYear, ByVal TheWeekday, ByVal TheOccurance)<BR><BR>Dim dtOut<BR>Dim dtLoop<BR>Dim iCnt, _<BR> iOccuranceCnt<BR> dtLoop = DateSerial(TheYear, TheMonth, 1)<BR><BR> While IsDate(dtOut) = False And Month(dtLoop) = TheMonth<BR> If Weekday(dtLoop) = TheWeekday Then<BR> iOccuranceCnt = iOccuranceCnt + 1<BR><BR> If iOccuranceCnt = TheOccurance Then<BR> dtOut = dtLoop<BR> End If<BR> End If<BR><BR> dtLoop = DateAdd("d", 1, dtLoop)<BR> Wend<BR><BR> GetXOccuranceOfWeekdayInMonth = dtOut<BR><BR>End Function<BR><BR><BR> If date1 &#062;= GetMemorialDay(Year(date1)) AND date1 &#060;= GetLaborDay(Year(date1)) Then<BR> Response.Write "Yes, " & date1 & " is between Memorial and Labor Days, inclusive."<BR> End If<BR><BR>%&#062;

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## So did you debug?

Silly question, probably. If you don&#039;t know how to use a function, then probably nobody ever taught you how to debug.<BR><BR>Okay, let me try it myself.<BR><BR>Those functions are more complicated than they need to be.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## LOL! Of course it doesn't work

Try this:<BR><BR>&#060;%<BR>date1 = 5/31/2004 <BR>Response.Write "DEBUG: date1 is " & date1<BR>%&#062;<BR><BR>Hmmmm????<BR><BR>If you are curious, you just set date1 to the value of 5 divided by 31 and then divided by 2004. <BR><BR>Now try this:<BR><BR>&#060;%<BR>date1 = #5/31/2004# <BR>Response.Write "DEBUG: date1 is " & date1<BR>%&#062;<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
115

## RE: dang now i really feel stupid, LOL

I knew dates needed the hash marks....yes it works fine with the hash marks LOL.<BR>Thanks Bill your a lifesaver.<BR>George

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Here...MUCH simplified code!

&#060;% <BR>&#039;The helper function: <BR>Function GetXOccuranceOfWeekdayInMonth(mn, yr, wkdy, count)<BR> Dim dt<BR> dt = DateSerial( yr, mn, 1 ) &#039; first of month<BR> Do Until WeekDay(dt) = wkdy<BR> dt = dt + 1<BR> Loop<BR> GetXOccuranceOfWeekdayInMonth = dt + 7 * ( count - 1 )<BR>End Function <BR><BR><BR>&#039; labor day is 1st Monday in september<BR>Function GetLaborDay(ByVal HolidayYear) <BR> GetLaborDay = GetXOccuranceOfWeekdayInMonth(9, HolidayYear, vbMonday, 1) <BR>End Function <BR><BR>&#039;Memorial Day is the 4th Monday of May: <BR>Function GetMemorialDay(ByVal HolidayYear) <BR> GetMemorialDay = GetXOccuranceOfWeekdayInMonth(5, HolidayYear, vbMonday, 4) <BR>End Function <BR><BR>&#039; test case<BR>date1 = #5/24/2004# &#039; but try same day in 2002 and 2003<BR><BR>mday = GetMemorialDay(Year(date1))<BR>lday = GetLaborDay(Year(date1))<BR>Response.Write "date1: " & date1 & "&#060;p&#062;mem day: " & mday & "&#060;p&#062;lab day: " & lday & "&#060;HR&#062;"<BR><BR>If date1 &#062;= mday AND date1 &#060;= lday Then <BR> Response.Write "Yes, " & date1 & " is between Memorial and Labor Days, inclusive." <BR>Else<BR> Response.Write "NOPE, " & date1 & " is NOT between Memorial and Labor Days, inclusive." <BR>End If<BR><BR>%&#062; <BR><BR>*************<BR><BR>The GetXOccurance... could be written without a DO loop, but it&#039;s actually simpler to use one. But once you get to the right day, then adding 7 * the number of weeks is much easier than the complex stuff that was there before.<BR><BR>And there&#039;s no need for the extraneous dtOut variable in the other two functions.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
115

## RE: One more question please?

one more thing i cant seem to find anywhere on the net is checking server time against a set time, here&#039;s what I tried and of course it errors on the : can you please point me in the right direction?<BR><BR>&#060;% if time &#062; 5:00 PM then<BR>response.write "&#060;FORM action=""http://somelink"" method=""post""&#062;"<BR>else<BR>response.write "&#060;FORM action=""http://someotherlink"" method=""post""&#062;"<BR>End If<BR><BR><BR>not sure what to try here.<BR>%&#062;

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## Exact same problem

You are forgetting the #...# around the time.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•