Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tricky Date Function 2

Status
Not open for further replies.

AintScared

Programmer
Aug 5, 2003
2
US
I am writing a program in which part of the requirements are to check if a date (input by user) is before or after the second Saturday of the current month. I pulled out my references for all the date functions and I'm pretty sure I will be able to figure it out using the Weekday, Datepart and Dateadd functions. Is there an easy and slick solution to this?

I am a fairly new programmer and can usually stumble through these sorts of things, but the code is typically less than elegant!

Thanks in advance for any help!

John
 
Try this little function, based on one I used to get the 3rd Thursday. Date should be validated with ISDATE first.

Public Function IsDate2ndSat(fdt As Date) As Boolean

Dim dst As String
Dim dow As Integer

dst = "01-" & Format(fdt, "mmm-yyyy")
dow = DatePart("w", dst)

If fdt = DateAdd("d", dow + ((7 - dow) * 2), dst) Then
IsDate2ndSat = True
End If

End Function


Hope you find this usefull.



 
Excellent Excellent Excellent!

This routine worked perfectly. The only change I needed to make was to change the = to a <= in the

If fdt = DateAdd(&quot;d&quot;, dow + ((7 - dow) * 2), dst) Then statement.

This is because I am trying to capture all days before or on the second Saturday.

My hat is off to you SonOfEmidec1100! Thanks so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top