0

I tried like as:

JS code:

 var today = new Date();
 var dd = today.getDate();
 var mm = today.getMonth()+6;
 var yyyy = today.getFullYear();

 $scope.maxDate = yyyy + '-' + mm + '-' + dd;

HTML code:

<input type="text" ng-click="open($event)" min-date="minDate" max-mode="maxDate" datepicker-options="dateOptions" class="form-control" datepicker-popup="{{format}}" ng-model="dtModel"/>
3
  • So, if the current date is 2015-11-28, the max date would be 2015-16-28? Commented Jun 6, 2015 at 20:44
  • 1
    what version of angular are you using? Commented Jun 6, 2015 at 20:47
  • 1
    You have a typo I think, it has to be "max-date", not "max-mode"? Commented Jun 6, 2015 at 20:50

2 Answers 2

3

Try this, should work :

var today = new Date();

$scope.maxDate = new Date(today.getFullYear(), today.setMonth()+6, today.getDate());

EDIT Sorry, my bad :

var today = new Date();
  today.setMonth(today.getMonth()+6);


  $scope.maxDate = new Date(today.getFullYear(),today.getMonth() , today.getDate());

I tested it on plunker : http://plnkr.co/edit/Qb9N0OjhHWIH9ChtbF1J?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

So, with this solution I can slide calendar to any year and select it
0

Change your max-mode to max-date as suggested by @ThomasWeglinski above.

And then change your 6 months from now calculation to this:

var sixMonthsFromNow = today.setMonth(today.getMonth()+6);
var dd = sixMonthsFromNow.getDate();
var mm = sixMonthsFromNow.getMonth();
var yyyy = sixMonthsFromNow.getFullYear();
$scope.maxDate = yyyy + '-' + mm + '-' + dd;

1 Comment

The OP isn't using a raw date inut fiels, but an angular-ui datepicker: angular-ui.github.io/bootstrap/#/datepicker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.