ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check Dates (https://www.excelbanter.com/excel-programming/309726-check-dates.html)

john

Check Dates
 
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



JE McGimpsey

Check Dates
 
Check out:

http://cpearson.com/excel/DateTimeVBA.htm#NDow


In article ,
"John" wrote:

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


Myrna Larson

Check Dates
 
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



On Sun, 12 Sep 2004 23:12:17 -0700, "John"
wrote:

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




All times are GMT +1. The time now is 02:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com