-4

i want compare the date and time and want show the differnce time in angularjs,i am gettig date in the format of yyyy/MM/dd,

praveen
  • 1
  • 2

2 Answers2

0

Apart from the fact that your question normally does not deserve an answer due to the lack of own code this has been answered multiple times on SO. Next time, you should add some more information about your problem and the code you are struggling with.

Anyway, I have a simple solution for you (powered by @Tni):

var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope) {
    $scope.date1 = '2015/01/01';
    $scope.date2 = '2015/12/31';
    
    $scope.getDateDiff = function() {
     var date1 = new Date($scope.date1),
            date2 = new Date($scope.date2),
            timeDiff = Math.abs(date2.getTime() - date1.getTime());
        $scope.dateDiff = 'Amount of days difference: ' + Math.ceil(timeDiff / (1000 * 3600 * 24)); 
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp" ng-controller="MyCtrl">
    Date 1: <input type="text" ng-model="date1">
    <br /><br />
    Date 2: <input type="text" ng-model="date2">
    <br /><br />
    <button ng-click="getDateDiff()">Get Date Diff!</button>
    <br /><br />
    {{dateDiff}}
</div>
Community
  • 1
  • 1
DonJuwe
  • 4,477
  • 3
  • 34
  • 59
-1

Please check this link, you will get better solution

JSFiddle Demo

html:

<div ng-app ng-controller="Ctrl"> 
   {{date | date:'dd-MM-yyyy hh:mm '}} <br>
</div>

js:

function Ctrl($scope)
{
    $scope.date = new Date(); 
}
Nehal
  • 13,130
  • 4
  • 43
  • 59