I am fairly new to angularjs, but here it goes. I am able two dates through angularjs in the form dd/mm/yyyy
, but what I need to do is somehow subtract the two dates to get the difference in days between the two. I created a jquery function to do this, but I don't know how to pass in the two dates to the function. So I was wondering if there was a different way to go about this?
I am trying to set up a trigger system depending on the number of days in between the two dates for certain things to be stylized. For example if it's within 10 days I want it to use style 1 and if its within 20 days use style 2 and so on.
Basic javascript way:
var d1 = new Date('01/16/2013');
var d2 = new Date('02/26/2013');
var milliseconds = d2-d1;
var seconds = milliseconds / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24;
Using one of the Date libraries (such as moment.js):
var d1 = moment("01/16/2013");
var d2 = moment("02/26/2013");
var days = moment.duration(d2.diff(d1)).asDays();
you simply convert date into timestamp and then subtract.
var Date1 = 08/16/2004;
var Date2= 10/24/2005;
var timestamp1 = new Date(Date1).getTime();
var timestamp2 = new Date(Date2).getTime();
var diff = timestamp1 - timestamp2
var newDate = new Date (diff);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With