Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find difference between 2 dates with AngularJS

Tags:

date

angularjs

I get 2 dates from MySQL something like this:

Start: 2015-11-01 22:56:59 End: 2015-11-03 00:00:00

Also I get dates from object array; here is what one object looks like:

Array[5]
0: Object
$$hashKey: "object:9"
created_at: "2015-10-23 03:36:11"
expiration_date: "2015-11-03 00:00:00"
id: 1
name: "TEST PROJECT"

I need to find how many days left with AngularJS...

like image 386
Vladimir Djukic Avatar asked Dec 05 '22 02:12

Vladimir Djukic


1 Answers

Its simple. Use the function as:

$scope.calcDiff = function(firstDate, secondDate){
    var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds    
    var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
}
like image 105
Emir Marques Avatar answered Jan 14 '23 14:01

Emir Marques