2

I have an input date-picker and I want to set its min value to the current date

<input type="date" class="form-control" id="checkindate" placeholder="" min="">

how can I do this using Angular?

  • Does this answer your question? [Set date input field's max date to today](https://stackoverflow.com/questions/32378590/set-date-input-fields-max-date-to-today) – Osama Bin Saleem Jul 07 '21 at 08:36

2 Answers2

1

There are multiple ways to do it. The min attribute accepts a string in multiple formats. Here is my solution using 'yyyy-mm-dd'.

Controller (*.ts)

export class AppComponent {
  currentDate: string;

  constructor() {
    // credit: https://stackoverflow.com/a/38148759/6513921
    this.currentDate = new Date().toISOString().slice(0, 10);
  }
}

Template (*.html)

<input type="date" class="form-control" id="checkindate" placeholder="" [min]="currentDate">

Working example: Stackblitz

ruth
  • 29,535
  • 4
  • 30
  • 57
0

You need to pipe the date to follow the input format.

Here Demo