#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if date is between two dates, then sum only those rows streetcar Excel Worksheet Functions 2 February 16th 10 12:19 PM
Error Check Dates jlclyde Excel Discussion (Misc queries) 1 December 22nd 08 09:13 PM
How can I check whether a column of dates are all before today's d PaladinWhite Excel Worksheet Functions 3 October 21st 07 05:52 PM
How can I check whether a column of dates are all before today's d PaladinWhite Excel Worksheet Functions 1 October 20th 07 04:50 AM
How to check for duplicates in a list of names and dates Robert,MofD Excel Discussion (Misc queries) 5 April 30th 05 11:54 PM


All times are GMT +1. The time now is 11:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"