How to count Wednesdays between two dates

home70

Registered User.
Local time
Today, 17:30
Joined
Jul 10, 2006
Messages
72
Is there a way to find out the number of Wednesdays between two given dates? Thank you.
 
from VB Help for datediff:

To calculate the number of days between date1 and date2, you can use either Day of year ("y") or Day ("d"). When interval is Weekday ("w"), DateDiff returns the number of weeks between the two dates. If date1 falls on a Monday, DateDiff counts the number of Mondays until date2. It counts date2 but not date1. If interval is Week ("ww"), however, the DateDiff function returns the number of calendar weeks between the two dates. It counts the number of Sundays between date1 and date2. DateDiff counts date2 if it falls on a Sunday; but it doesn't count date1, even if it does fall on a Sunday.
 
Thanks for your reply. I already use DateDiff to get the number of weeks between dates. I now need a more exact calculation.
 
Is there a way to find out the number of Wednesdays between two given dates?

DateDiff("ww", [StartDate], [EndDate], 4) -(Weekday([StartDate]) = 4)

.
 
DateDiff("ww", [StartDate], [EndDate], 4) -(Weekday([StartDate]) = 4)

.

Thanks but it's not working for me. In a query it tells me that it doesn't like the last ) and as the controlsource of a text box it gives me #Name?
What do you think? Am I doing something wrong?
 
That string works for me. I made a form with 3 textboxes. I named one StartDate and entered 1/1/2007. I named one EndDate and entered 1/31/2007. and I entered =DateDiff("ww", [StartDate], [EndDate], 4) -(Weekday([StartDate]) = 4) in the ControlSource of the third textbox. After entering the dates in the first two textboxes, the third reads 5.
 
Originally Posted by home70
Thanks but it's not working for me. In a query it tells me that it doesn't like the last ) and as the controlsource of a text box it gives me #Name?
What do you think? Am I doing something wrong?
Dudley has shown you how to do it in the control source of a text box on a form.

As for doing it in a query, please see the query in the attached database.
.
 

Attachments

Thanks to all of you for your help!
I hope you all have a good day.
 

Users who are viewing this thread

Back
Top Bottom