2

This is my code:

$scope.date = new Date();
var date1 = new Date($scope.date);
var date2 = new Date(2017,5,5);
var diffDays = parseInt((date2 - date1) / (1000 * 60 * 60 * 24));
alert(diffDays);

the above code is working fine, but when I try pass model in js its not working, it is showing NaNinstead.

Here is my controller with model value

$scope.date = new Date();
var date1 = new Date($scope.date);
var date2 = new Date($scope.studyUser.Ethical_Committee_Approved_Date);
var diffDays = parseInt((date2 - date1) / (1000 * 60 * 60 * 24));
alert(diffDays);

here is my html code

<div class="col-sm-7">
<p class="input-group">
<input type="text" class="form-control" id="Ethical_Committee_Approved_Date"                                                
uib-datepicker-popup="{{format}}"
is-open="datePicker.popup1.opened"
ng-model="studyUser.Ethical_Committee_Approved_Date"
datepicker-options="datePicker.dateOptions"
ng-required="true"
onkeydown="return false"
ng-click="datePicker.open1($event)"
readonly
alt-input-formats="altInputFormats"
ng-change="datePicker.changeMinAndMaxDates()">
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="datePicker.open1($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>                                            
</p>
<span style="color:red" ng-show="addstudy.approvaldate.$invalid && addstudy.approvaldate.$dirty">Please Enter the Approval Date</span>
</div>
waka
  • 3,362
  • 9
  • 35
  • 54
  • If you are ok with using external library. Check `momentjs`. It will help you a lot with dates manipulation – Weedoze Mar 07 '17 at 07:19
  • 3
    Possible duplicate of [How to subtract two angularjs date variables](http://stackoverflow.com/questions/15298663/how-to-subtract-two-angularjs-date-variables) – Mahendran Nadesan Mar 07 '17 at 07:19

0 Answers0