JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<div ng-app="myApp" name="date" ng-controller="MainCtrl">
<input type="text" ng-model="firstDate" datepicker/>
<h3> First date: {{firstDate}}</h3>
<input type="text" name="date" ng-model="secondDate" datepicker/>
<button ng-click="dayDiff(firstDate,secondDate)">calculate</button>
<h3> Second date: {{secondDate}}</h3>
<h2>Day Difference: {{dayDifference}} </h2>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl', function($scope) {
$scope.dayDiff = function(firstDate,secondDate){
$scope.dayDifference = parseInt(Math.round((secondDate - firstDate) / (1000 * 60 * 60 * 24)));;
}
});
myApp.directive('datepicker', function() {
return {
restrict: 'A',
require : 'ngModel',
link : function (scope, element, attrs, ngModelCtrl) {
$(function(){
element.datepicker({
dateFormat:'dd/mm/yy',
onSelect:function (date) {
ngModelCtrl.$setViewValue(date);
scope.$apply();
}
});
});
}
}
});