Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Date/Time: How many Sundays between two dates

Author(s)
Michel Walsh

    From an initial observation made by Lyle Fairfield, here a solution to get the number of, let's say, Wednesday, between two dates:

'************* Code Start *************
Public Function HowManyWD(FromDate As Date, _
                            ToDate As Date, _
                            WD As Long)
   ' No error handling actually supplied
    HowManyWD = DateDiff("ww", FromDate, ToDate, WD) _
                                 - Int(WD = WeekDay(FromDate))
End Function
'************* Code End *************

    In the same way, someone can easily get the number of weekdays (excluding weekends) by subtracting number of Sundays and Saturdays:

'************* Code Start *************
Public Function HowManyWeekDay(FromDate As Date, _
                            ToDate As Date, _
                            Optional ToDateIsIncluded As Boolean = True)
    
    HowManyWeekDay = DateDiff("d", FromDate, ToDate) - _
                    ToDateIsIncluded - _
                    HowManyWD(FromDate, ToDate, vbSunday) - _
                    HowManyWD(FromDate, ToDate, vbSaturday)
End Function
'************* Code End *************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer