Count the number of weekdays between two dates in visual basic

后端 未结 6 1232
我寻月下人不归
我寻月下人不归 2021-01-14 21:48

I\'m a SQL guy, but I need a function to calculate the number of weekdays between two dates in VB.NET. I don\'t need to worry about holidays. My attempts unfortunately have

6条回答
  •  醉酒成梦
    2021-01-14 22:19

    I have an expression that will calculate amount of specific day of week between two dates. So if you add amount on Mondays, Tuesdays ... Fridays you will get the amount of week days.

    =SUM(int((DatePart("d",Fields!dteEndDateTime.Value) - Weekday(DateAdd("d",1-**[DayofWeek]**,Fields!dteEndDateTime.Value)) - DatePart("d",Fields!dteStartDateTime.Value) + 8)/7))
    

    [DayofWeek] is an integer representing a day: 1 - Sunday; 2 - Monday

    So an expression that will calculate amount of Mondays between dteStartDateTime and dteEndDateTime is:

    =SUM(int((DatePart("d",Fields!dteEndDateTime.Value) - Weekday(DateAdd("d",1-2,Fields!dteEndDateTime.Value)) - DatePart("d",Fields!dteStartDateTime.Value) + 8)/7)) 
    

提交回复
热议问题