429,558 Members | 1,373 Online
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

# Find every saturday and sunday in an interval of two dates

 P: 3 Hello. I've been working on a program for several days and I already have a few thousands of lines of codes written. But I'm facing with a big dilemma right now. I'm kind of new to .NET, I'm working in Visual Studio 2013. I'm trying to find an easiest way to do the following: I've got these objects: DateTimePicker1 DateTimePicker2 ListBox1 Button1 Label1 Label2 In the DateTimePicker1, the user chooses the starting date. Let's say 1. january 2014. In the DateTimePicker2, the user chooses the ending date. Let's say 1. july 2014. Now, what I need the program to do is that when the user clicks on Button1, the following will show up in Label1 and Label2: Label1 will show total days in a number in between the dates chosen in DateTimePicker 1 and 2. label2 will show total days in a number in between the dates chosen in DateTimePicker 1 and 2 WITHOUT every sunday and saturday that occurs in between these two dates. Also, every saturday's and sunday's dates in between the dates chosen in DateTimePicker 1 and 2 will be added to the ListBox1. Is there anyone who could help me out? It's an important project to me and I still have about 40% of coding left, but this is stopping me. I can't continue working on my program until I get this solved. Thank you very much. Jan 21 '14 #1
4 Replies

 Expert Mod 10K+ P: 12,359 What have you tried so far and what errors are you getting? Jan 21 '14 #2

 P: 3 Well I was trying lots of things. I know the code to count all of the days in between that interval: Expand|Select|Wrap|Line Numbers Dim date1 As Date Dim date2 As Date   date1 = Convert.ToDateTime(DateTimePicker1.Value) date2 = Convert.ToDateTime(DateTimePicker2.Value) Dim diff As System.TimeSpan = date2 - date1 Label1.Text = diff.Days + 1 And I was trying to use While, For and so on to somehow get all the dates of weekdays to be written in the ListBox1, but I can't figure out a proper way. I found some code to count all of the fridays in a specified date range, but it didn't fit my case. Also, I couldn't get the dates to be written in ListBox1 as separate items. And due to it's format being DateTime, not Date even after I wrote Date only, it was writing the items as e.g. 25.4.2014; 17:32... but I don't want the time to be there. I believe it's due to the DateTimePicker's DateTime only format being available. Jan 21 '14 #3

 Expert Mod 10K+ P: 12,359 Please show me the loop you tried. Jan 21 '14 #4

 P: 3 I've got my question already answered. Thank you anyways :) http://stackoverflow.com/questions/2...s-interval-net Jan 21 '14 #5