DateTime picker doesn't allow you to select date that falls within 'min' and 'max' range
Short description of the problem:
The available values on the DateTime picker doesn't update when you select a different month / year. You have to first select a date for it to update.
What behavior are you expecting?
When you select a different month or year, the available days (or months) should update.
Steps to reproduce:
- Create a 'ion-datetime' component.
- Set the 'min' attribute to the start of the current day (UTC).
- Set the 'max' attribute to the end of next year (UTC).
- Try and select a date in the next year, but less than 365 days away.
// setting of the 'min' and 'max' values
this.minDate = moment.utc().startOf('day').format('YYYY-MM-DD');
this.maxDate = moment.utc().add(1, 'y').format('YYYY-MM-DD');
<!-- usage in html -->
<ion-item>
<ion-label>Start date</ion-label>
<ion-datetime displayFormat="D MMM YYYY" min="{{minDate}}" max="{{maxDate}}" placeholder="Select start date" [ngFormControl]="startTime" [(ngModel)]="campaignData.startTime"> </ion-datetime>
</ion-item>
Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)
Screenshot showing that Jan - May 2017 is not available for selection, even though they fall within the 'min' and 'max' range specified for the DateTIme picker:

Which Ionic Version? 1.x or 2.x 2.x (beta 7)
ionic info output from terminal:
Your system information:
Cordova CLI: 6.1.1
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.7
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v4.4.4
Xcode version: Xcode 7.3.1 Build version 7D1014
Could you try binding to the min and max property instead of using the braces? Like this:
<ion-item>
<ion-label>Start date</ion-label>
<ion-datetime displayFormat="D MMM YYYY" [min]="minDate" [max]="maxDate" placeholder="Select start date" [ngFormControl]="startTime" [(ngModel)]="campaignData.startTime"></ion-datetime>
</ion-item>
Thanks for the suggestion!
I changed the binding within the HTML to the following:
<ion-datetime displayFormat="D MMM YYYY" min="minDate" max="maxDate" placeholder="Select start date" [ngFormControl]="startTime" [(ngModel)]="campaignData.startTime"></ion-datetime>
But I got the following error:
14 218348 error EXCEPTION: Error in build/pages/campaign-create/campaign-create.html:26:4
15 218349 error ORIGINAL EXCEPTION: TypeError: null is not an object (evaluating 'min.month')
16 218349 error ORIGINAL STACKTRACE:
18 218350 error ERROR CONTEXT:
17 218350 error calcMinMax@http://172.16.6.183:8100/build/js/app.bundle.js:46903:24
generate@http://172.16.6.183:8100/build/js/app.bundle.js:46710:28
open@http://172.16.6.183:8100/build/js/app.bundle.js:46689:22
_click@http://172.16.6.183:8100/build/js/app.bundle.js:46653:18
_handle_click_15_1
[native code]
http://172.16.6.183:8100/build/js/app.bundle.js:29193:36
http://172.16.6.183:8100/build/js/app.bundle.js:38140:48
http://172.16.6.183:8100/build/js/app.bundle.js:38210:100
invoke@http://172.16.6.183:8100/build/js/zone.min.js:1:7220
onInvoke@http://172.16.6.183:8100/build/js/app.bundle.js:33771:47
invoke@http://172.16.6.183:8100/build/js/zone.min.js:1:7174
runGuarded@http://172.16.6.183:8100/build/js/zone.min.js:1:4796
runInnerGuarded@http://172.16.6.183:8100/build/js/app.bundle.js:33804:88
runGuarded@http://172.16.6.183:8100/build/js/app.bundle.js:33708:88
outsideHandler@http://172.16.6.183:8100/build/js/app.bundle.js:38210:71
invokeTask@http://172.16.6.183:8100/build/js/zone.min.js:1:7851
runTask@http://172.16.6.183:8100/build/js/zone.min.js:1:5214
invoke@http://172.16.6.183:8100/build/js/zone.min.js:1:8962
dispatchEvent@[native code]
touchEnd@http://172.16.6.183:8100/build/js/app.bundle.js:63781:44
[native code]
hi remove {} not [] see below
<ion-datetime displayFormat="D MMM YYYY" [min]="minDate" [max]="maxDate"
Oops! Thanks for the correction @evgeniynet.
This fixed the exception I was having, but the end result was still the same:

Here is the related code:
HTML:
<ion-item>
<ion-label>Start date</ion-label>
<ion-datetime displayFormat="D MMM YYYY" [min]="minDate" [max]="maxDate" placeholder="Select start date" [ngFormControl]="startTime" [(ngModel)]="campaignData.startTime"></ion-datetime>
</ion-item>
...
<ion-item *ngIf="!campaignData.runContinuosly">
<ion-label>End date</ion-label>
<ion-datetime displayFormat="D MMM YYYY" [min]="minDate" [max]="maxDate" placeholder="Select end date" [ngFormControl]="endTime" [(ngModel)]="campaignData.endTime">
</ion-datetime>
</ion-item>
JavaScript:
...
this.minDate = moment().startOf('day').format('YYYY-MM-DD');
this.maxDate = moment().add(1, 'y').format('YYYY-MM-DD');
...
Using ionic-angular version 2.0.0-beta.8-201606091959 I am getting an error when trying this approach.
<ion-datetime displayFormat="MMM D, YYYY h:mm A"[(ngModel)]="concert.dateTime"
[min]="minDateTime" [max]="maxDateTime">
</ion-datetime>
minDateTime() {
return moment().subtract(30, 'days').format();
}
maxDateTime() {
return moment().format();
}
browser_adapter.js:77 EXCEPTION: Error in build/pages/tanker-setup/tanker-setup.html:56:8BrowserDomAdapter.logError @ browser_adapter.js:77BrowserDomAdapter.logGroup @ browser_adapter.js:87ExceptionHandler.call @ exception_handler.js:57(anonymous function) @ application_ref.js:265schedulerFn @ async.js:123SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:112NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:120NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:66ZoneDelegate.handleError @ zone.js:327Zone.runGuarded @ zone.js:233NgZoneImpl.runInnerGuarded @ ng_zone_impl.js:78NgZone.runGuarded @ ng_zone.js:228outsideHandler @ dom_events.js:20ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
browser_adapter.js:77 ORIGINAL EXCEPTION: TypeError: Cannot read property 'month' of nullBrowserDomAdapter.logError @ browser_adapter.js:77ExceptionHandler.call @ exception_handler.js:66(anonymous function) @ application_ref.js:265schedulerFn @ async.js:123SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:112NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:120NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:66ZoneDelegate.handleError @ zone.js:327Zone.runGuarded @ zone.js:233NgZoneImpl.runInnerGuarded @ ng_zone_impl.js:78NgZone.runGuarded @ ng_zone.js:228outsideHandler @ dom_events.js:20ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
browser_adapter.js:77 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.js:77ExceptionHandler.call @ exception_handler.js:69(anonymous function) @ application_ref.js:265schedulerFn @ async.js:123SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:112NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:120NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:66ZoneDelegate.handleError @ zone.js:327Zone.runGuarded @ zone.js:233NgZoneImpl.runInnerGuarded @ ng_zone_impl.js:78NgZone.runGuarded @ ng_zone.js:228outsideHandler @ dom_events.js:20ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
browser_adapter.js:77 TypeError: Cannot read property 'month' of null
at DateTime.calcMinMax (datetime.js:571)
at DateTime.generate (datetime.js:370)
at DateTime.open (datetime.js:349)
at DateTime._click (datetime.js:313)
at DebugAppView._View_TankerSetupPage0._handle_click_62_1 (TankerSetupPage.template.js:1286)
at view.js:316
at dom_renderer.js:278
at dom_events.js:20
at ZoneDelegate.invoke (zone.js:323)
at Object.NgZoneImpl.inner.inner.fork.onInvoke (ng_zone_impl.js:45)
Cordova CLI: 6.1.1 Gulp version: CLI version 3.9.1 Gulp local: Local version 3.9.1 Ionic Framework Version: 2.0.0-beta.8-201606091959 Ionic CLI Version: 2.0.0-beta.25 Ionic App Lib Version: 2.0.0-beta.15 ios-deploy version: 1.8.5 ios-sim version: 3.1.1 OS: Mac OS X El Capitan Node Version: v5.8.0 Xcode version: Xcode 7.3.1 Build version 7D1014
Hello all! I am going to be closing this issue as a duplicate of https://github.com/driftyco/ionic/issues/6850. You can follow that issue for updates on this bug. Thanks for using Ionic!
hi @devillex ,
I saw that you used placeholder in <ion-datetime> , does it works for you? because I tried so in ionic 2 but does not displays placeholder text for me.
my code: <ion-datetime class="dateTime" placeholder="Start Date" pickerFormat="D MMMM YYYY" displayFormat="YYYY-MM-DD" [(ngModel)]="startDate"></ion-datetime>
We don't use the placeholder any longer and I've since removed it from the code as well. We set the initial value to the current date and time.
hi,
I'm trying to use ionic 2 datepicker, it works but when I want to use min & max properties it doesn't work.
<ion-datetime displayFormat="DD-MM-YYYY" [min]="today" [(ngModel)]="event.date.start">
'today': moment().format("YYYY-MM-DD")
It filter date only on years ! But I would like to have custom day and month.
Kindly Advice me,
Thanks & Regards
@anivaisu Try this:
<ion-datetime max="2018" [min]="today()" displayFormat="DD MMM YYYY" [(ngModel)]="poll.expiredAt" doneText="Update" (ngModelChange)="updateDueDate($event)"></ion-datetime>
.ts file
public today() {
return new Date().toISOString().substring(0,10);
}
Hi, I have one problem with ion-datetime. I am try to get only date along with time.
The picker is good. But when I get selected date and time then, I get only time into ngModel variable.
Can you explain about problem
<ion-datetime displayFormat="DD h:mm A" [(ngModel)]="FromDate"></ion-datetime>

OUTPUT : "01:00"
Thank you
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.