I want to limit the Angular UI Datepicker to be between two dates passed in as variables. Here is a working plunker of this problem: http://plnkr.co/edit/zsjpoVZtHqJLIP2RW6vm?p=preview
here are the variables:
mycurrentdate = '2016-04-15'
mymindate = '2016-04-01'
mymaxmonth = '2016-05-01'
My actual max date will be the end of mymaxmonth, so in this case: '2016-05-31'
$scope.maxDate = new Date(
$scope.mymaxmonth + (TO THE END OF THE MONTH)
);
One thing to note is that running it through new Date()
returns a date that is the day before the given date. For example:
$scope.minDate = new Date(
$scope.mymindate
);
where $scope.minDate returns Wed Mar 30 2016 17:00:00 GMT-0700 (PDT)
I looked up the reason for why it returns March 30 instead of April 1st and it seems like a timezone error?
I want to set a mymindate of '2016-04-01' and get mymaxdate = '2016-05-31' and disable all dates outside of this range. I am especially hung up on figuring out how to get to the end of the month. Is there some endofmonth() function in javascript?
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.mymindate
);
$scope.maxDate = new Date(
$scope.mymaxmonth + 1
);
In the template I have:
<p class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="popup1.opened" min="minDate" max="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>