
help with dates...please
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><%<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>'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>'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 > getmemorialday OR date1 < dtout then<BR>response.write "yes"<BR>End if<BR>%><BR><BR>Also, thanks God for your help yesterday<BR>George

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 > 5 OR 3 < 9 Then<BR><BR>Well, 3 is not > 5, but it *IS* < 9. So your logic would be saying "Yep, March must be between May and September."<BR><BR>Whereas:<BR> If 3 > 5 AND 3 < 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'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 >= GetMemorialDay(Year(date1)) AND date1 <= GetLaborDay(Year(date1)) Then<BR> Response.Write "Yes, " & date1 & " is between Memorial and Labor Days, inclusive."<BR> End If<BR><BR>

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

RE: Still doesnt work
Still doesnt work....<BR><BR><BR><%<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>'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>'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 >= GetMemorialDay(Year(date1)) AND date1 <= GetLaborDay(Year(date1)) Then<BR> Response.Write "Yes, " & date1 & " is between Memorial and Labor Days, inclusive."<BR> End If<BR><BR>%>

So did you debug?
Silly question, probably. If you don'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>

LOL! Of course it doesn't work
Try this:<BR><BR><%<BR>date1 = 5/31/2004 <BR>Response.Write "DEBUG: date1 is " & date1<BR>%><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><%<BR>date1 = #5/31/2004# <BR>Response.Write "DEBUG: date1 is " & date1<BR>%><BR><BR>

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

Here...MUCH simplified code!
<% <BR>'The helper function: <BR>Function GetXOccuranceOfWeekdayInMonth(mn, yr, wkdy, count)<BR> Dim dt<BR> dt = DateSerial( yr, mn, 1 ) ' 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>' labor day is 1st Monday in september<BR>Function GetLaborDay(ByVal HolidayYear) <BR> GetLaborDay = GetXOccuranceOfWeekdayInMonth(9, HolidayYear, vbMonday, 1) <BR>End Function <BR><BR>'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>' test case<BR>date1 = #5/24/2004# ' but try same day in 2002 and 2003<BR><BR>mday = GetMemorialDay(Year(date1))<BR>lday = GetLaborDay(Year(date1))<BR>Response.Write "date1: " & date1 & "<p>mem day: " & mday & "<p>lab day: " & lday & "<HR>"<BR><BR>If date1 >= mday AND date1 <= 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>%> <BR><BR>*************<BR><BR>The GetXOccurance... could be written without a DO loop, but it'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's no need for the extraneous dtOut variable in the other two functions.<BR><BR>

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's what I tried and of course it errors on the : can you please point me in the right direction?<BR><BR><% if time > 5:00 PM then<BR>response.write "<FORM action=""http://somelink"" method=""post"">"<BR>else<BR>response.write "<FORM action=""http://someotherlink"" method=""post"">"<BR>End If<BR><BR><BR>not sure what to try here.<BR>%>

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

Forum Rules

