title: How to disable Future date in DatePicker in Kotlin Android
body: <p>I am using DatePickerDialog in my Android project using Kotlin. I have successfully created DatePickerDialog and its working fine.
       Now I want to give some validation like in DatePickerDialog I want to disable future date.
  For Example, Today date is 22 Aug 2019 I want to disable all date after today date.</p>
  
  <p>I tried to use <code>dateSetListener.getDatePicker().setMaxDate(System.currentTimeMillis())</code></p>
  
  <p>but it's not working</p>
  
  <pre class="lang-java prettyprint-override"><code>var cal = Calendar.getInstance()
  
        // create an OnDateSetListener
  
          val dateSetListener = object : DatePickerDialog.OnDateSetListener {
  
          override fun onDateSet(
              view: DatePicker, year: Int, monthOfYear: Int,
              dayOfMonth: Int
          ) {
              cal.set(Calendar.YEAR, year)
              cal.set(Calendar.MONTH, monthOfYear)
              cal.set(Calendar.DAY_OF_MONTH, dayOfMonth)
              updateDateInView()
  
          }
  
         // dateSetListener.getDatePicker().setMaxDate(calendar.getTimeInMillis());
      }
  
      // when you click on the button, show DatePickerDialog that is set with OnDateSetListener
      button_date!!.setOnClickListener(object : View.OnClickListener {
          override fun onClick(view: View) {
  
              DatePickerDialog(this@MainActivity,
                  dateSetListener,
                  // set DatePickerDialog to point to today's date when it loads up
                  cal.get(Calendar.YEAR),
                  cal.get(Calendar.MONTH),
                  cal.get(Calendar.DAY_OF_MONTH)).show()
              }
      })```
  </code></pre>