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,
Asked
Active
Viewed 42 times
-4
-
Cool, and I want to build a new Facebook, plz plz. – Chrillewoodz Sep 08 '15 at 13:36
-
4Please post the code you have tried so far and the result you got, and what you are trying to achieve. – Dan Lowe Sep 08 '15 at 13:43
2 Answers
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>
-1
Please check this link, you will get better solution
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

angularkings
- 1
- 1