title: How to count number of days between date range material picker in android
body: <p><strong>How to count the number of days between date range picker</strong></p>
  <p><em>I am  Trying but no solution for this please anyone can help me</em></p>
  <p>I badly need count of days
  when user select date range form datepicker range
  then set text total count of days .</p>
  <pre><code>    try {
  
          String valu1 = String.valueOf(constraintsBuilder.setStart(calendar.getTimeInMillis()));
          String valu2 = String.valueOf(constraintsBuilder.setEnd(calendar.getTimeInMillis()));
          SimpleDateFormat simpleDateFormat = new SimpleDateFormat(&quot;dd-MMM-yyyy&quot;);
          Date date1 = simpleDateFormat.parse(valu1);
          Date date2 = simpleDateFormat.parse(valu2);
          long difference = Math.abs(date1.getTime() - date2.getTime());
  
          Log.i(&quot;Testing&quot;,&quot;days&quot; +difference);
          textView.setText(&quot;days&quot; +difference);
  
      }
      catch(Exception ex)
      {
  
          ex.printStackTrace();
      }
  </code></pre>
  <p>main code is</p>
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      showDatePicker= findViewById(R.id.showDatepicker);
      textView=findViewById(R.id.textView);
  
      Calendar calendar =Calendar.getInstance(TimeZone.getTimeZone(&quot;UTC+06&quot;));
   calendar.clear();
  
      MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.dateRangePicker();
      builder.setTitleText(&quot;Select Date&quot;);
    
  
  
      final MaterialDatePicker materialDatePicker = builder.build();
  
      showDatePicker.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              materialDatePicker.show(getSupportFragmentManager(),&quot;DATE_PICKER&quot;);
  
          }
      });
  
  
      materialDatePicker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
          @Override
          public void onPositiveButtonClick(Object selection) {
  
              showDatePicker.setText(materialDatePicker.getHeaderText());
  
  
          }
      });
  }
  </code></pre>