1,105,288 Community Members

Getting Interval of date excluding the sunday

Member Avatar
chocomilk
Newbie Poster
14 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am developing a code where im getting the interval of two dates
for example
DTLeavePayFrom = 1/1/2013
DTLeavePayTo = 1/14/2013

since 1/1/2013 is tuesday and 1/14/2013 is monday, the date diff of both date is 14
but how can i exclude the count of 2 sundays,

i have an existing code of date diff:

        Dim daycount As Integer = DateDiff(DateInterval.Day, DTLeavePayFrom.Value, DTLeavePayTo.Value)

Please help me, Thanks alot!

Member Avatar
poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 29 [?]
Q&As Helped to Solve: 78 [?]
Skill Endorsements: 9 [?]
 
0
 

Label1 will display the number of days....

          Dim count = 0
          Dim totalDays = (DTLeavePayTo.Value - DTLeavePayFrom.Value).Days
          Dim startDate As Date

          For i = 0 To totalDays
               Dim weekday As DayOfWeek = startDate.AddDays(i).DayOfWeek
               If weekday <> DayOfWeek.Sunday Then
                    count += 1
               End If
          Next
          Label1.Text = count
Member Avatar
chocomilk
Newbie Poster
14 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks, it helps alot! problem solved :)

Question Answered as of 1 Year Ago by poojavb
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article