Find every saturday and sunday in an interval of two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Satoshi96
    New Member
    • Jan 2014
    • 3

    Find every saturday and sunday in an interval of two dates

    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.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What have you tried so far and what errors are you getting?

    Comment

    • Satoshi96
      New Member
      • Jan 2014
      • 3

      #3
      Well I was trying lots of things. I know the code to count all of the days in between that interval:
      Code:
      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.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Please show me the loop you tried.

        Comment

        • Satoshi96
          New Member
          • Jan 2014
          • 3

          #5
          I've got my question already answered. Thank you anyways :)

          Comment

          Working...