We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Getting Interval of date excluding the sunday

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!

2
Contributors
2
Replies
22 Hours
Discussion Span
4 Months Ago
Last Updated
3
Views
Question
Answered
chocomilk
Newbie Poster
13 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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
poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 39
Solved Threads: 77
Skill Endorsements: 5

thanks, it helps alot! problem solved :)

chocomilk
Newbie Poster
13 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 4 Months Ago by poojavb

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0623 seconds using 2.63MB