title: How to calculate the working(excluding weekends) days in between two different dates in JAVA?
body: <p>My requirement is to calculate the number of <strong>Days</strong> between the given two dates, excluding <strong>Saturday</strong> and <strong>Sunday</strong>.</p>
  
  <p><strong>Example:</strong> </p>
  
  <pre><code>Start date - 10/09/15 and End date 18/09/15
  
  Result: 7
  </code></pre>
  
  <p>Date is in <code>DD/MM/YY</code> format.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import java.io.InputStreamReader;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Scanner;
  
  
  public class DaysCounter {
      private String startDate;
      private String endDate;
  
      public void calculateDate(){
          @SuppressWarnings("resource")
          Scanner in=new Scanner(new InputStreamReader(System.in));
  
          System.out.println("Enter the starting date (DD/MM/YY) :");
          startDate=in.next();
  
          System.out.println("Enter the End date (DD/MM/YY) :");
          endDate=in.next();
  
          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          try
          {
              Calendar start = Calendar.getInstance();
              start.setTime(sdf.parse(startDate));
              Calendar end = Calendar.getInstance();
              end.setTime(sdf.parse(endDate));
              int workingDays = 0;
              while(!start.after(end))
              {
                  int day = start.get(Calendar.DAY_OF_WEEK);
                  if ((day != Calendar.SATURDAY) &amp;&amp; (day != Calendar.SUNDAY))
                      workingDays++;
                  start.add(Calendar.DATE, 1);
              }
              System.out.println(workingDays);
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args)
      {
          DaysCounter daysCounter=new DaysCounter();
          daysCounter.calculateDate();
      }
  }
  </code></pre>
  
  <p>Here are the results for the above code.</p>
  
  <p><strong>1 -</strong> </p>
  
  <pre><code>Enter the starting date (DD/MM/YY) :
  14/09/15
  Enter the End date (DD/MM/YY) :
  20/09/15
  
  5
  </code></pre>
  
  <p><strong>2 -</strong></p>
  
  <pre><code>Enter the starting date (DD/MM/YY) :
  14/09/15
  Enter the End date (DD/MM/YY) :
  17/09/15
  
  2
  </code></pre>
  
  <p><strong>3 -</strong></p>
  
  <pre><code>Enter the starting date (DD/MM/YY) :
  31/08/15
  Enter the End date (DD/MM/YY) :
  30/09/15
  
  21
  </code></pre>
  
  <p>As seen in the above 1st example the result is correct.</p>
  
  <p>But for the second example the result is incorrect, <strong>expected result is 4</strong>.</p>
  
  <p>Even the third example, result is incorrect.</p>
  
  <p>Even when I enter the date between any weekday and a Saturday getting an incorrect result.</p>
  
  <p>Kindly suggest, what changes should be made to the code.</p>
  
  <p>Thanks.</p>