I want to restrict the Angular UI Datepicker parameter between two dates passed as variables. Preferably, I would like it to work without adding a library like momentjs, because this is the only field I need to work with dates in.
Here is the plank of this problem:
http://plnkr.co/edit/zsjpoVZtHqJLIP2RW6vm?p=preview
here are the variables:
mycurrentdate = '2016-04-18' mymindate = '2016-04-01' mymaxmonth = '2016-05-01' mymaxdate will be calculated from mymaxmonth to be mymaxdate = '2016-05-31'
My actual maximum date will be the last day of mymaxmonth
$scope.maxDate = new Date( $scope.mymaxmonth + (TO THE END OF THE MONTH) );
It should be noted that running it through new Date() returns a date that is a day before the specified date. For instance:
$scope.minDate = new Date( $scope.mymindate );
$ scope.minDate returns Wed Mar 30 2016 17:00:00 GMT-0700 (PDT) I searched for the reason why it returns March 30 instead of April 1, and it seems that this is a time zone error?
I want to set mymindate from '2016-04-01' and get mymaxdate = '2016-05-31' and disable all dates outside this range. I read the Javascript Date and Time Starter Guide and tried it here.
In the controller, I have:
$scope.mymindate = '2016-04-01'; $scope.mymaxmonth = '2016-05-01'; //want mymaxdate to be '2016-05-31' $scope.minDate = new Date($scope.dt.getFullYear(), $scope.dt.getMonth(), 1); $scope.maxDate = new Date($scope.dt.getFullYear(), $scope.dt.getMonth() + 1, 0);
In the template, I:
<p class="input-group"> <input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="popup1.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button> </span> </p>