Angular 4 Date-Picker - How to restrict Future and Past Days
18,623
bsDatepicker has a property [minDate]
and [maxDate]
, so you set those to "today" and inside your components constructor you do:
component.ts
today=new Date();
component.html
<input ... bsDatepicker ... [minDate]="today" [maxDate]="today" ... >
Anyway, having a datepicker when you don't really allow the user to select a date other than today makes no sense, you might as well default it to "today".
Related videos on Youtube
Author by
D.Sridhar
Currently working in Angular Domain.I am interested to making android apps and Gaming apps. Reach me out for any work here [email protected]
Updated on June 04, 2022Comments
-
D.Sridhar almost 2 years
I want to restrict the future and past days using Angular 4 Date-Picker.I just want to enable Current Date[today] only.How can i solve this.
Can anyone have idea...???
This is my template:
<input type="text" placeholder="FromDate" class="form-control" placement="top" formControlName="fromDate" [bsConfig]="{ dateInputFormat: 'DD-MM-YYYY' }" bsDatepicker style="padding: 16px">
-
rmcsharry almost 6 yearsIt depends on how you have implemented your date-picker. Can you post your date-picker code please?
-
D.Sridhar almost 6 years@rmcsharry <input type="text" placeholder="FromDate" class="form-control" placement="top" formControlName="fromDate" [bsConfig]="{ dateInputFormat: 'DD-MM-YYYY' }" bsDatepicker style="padding: 16px">
-
-
maury844 almost 6 yearsIf this answered your question make sure to mark it as accepted or upvote so it can help other people with the same issue. Thanks!
-
D.Sridhar almost 6 yearshow to tranform that DATE-FORMAT from "DD-MM-YYYY" into "YYYY-MM-DD" while clicks on submit... my template should be "params.Date = this.LicenseForm.value.Date"