Check Dates

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

How can i check that the date is sunday and it is the 2nd
week sunday of the month in VBA?

thanks.

regards,
John
 
If Weekday(TheDate) = 1 Then
'it's a Sunday
D = Day(TheDate)
If D >= 8 And D <= 14 Then
'it is the 2nd Sunday

The 1st Sunday must occur between the 1st and 7th of the month, the 2nd
between the 8th and 14th, 3rd between the 15th and 21st, 4th between the 22nd
and 28th, 5th between the 29th and end of month.

The formula to determine which it is, is

D = Day(TheDate)
WhichOne = ((D - 1) \ 7) + 1

so the above could be generalized so you could specify which day of the week
and which one:

WhichDay = vbSunday
WhichOne = 2

If Weekday(TheDate) = WhichDay Then
'the right day of the week
D = Day(TheDate)
If ((D - 1) \ 7) + 1 = WhichOne Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top