0

I have this code that gives me the number difference between dates and it works well, but if the result it's negative I would like to add the - before the number and if its positive have a + before the number. How would I do that?

var item = '2014-08-30';
var today = '2014-09-04';
var date1 = new Date(today);
var date2 = new Date(item);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
Alessandro Incarnati
  • 7,018
  • 3
  • 38
  • 54
James Suske
  • 91
  • 2
  • 13

1 Answers1

0

But you allready have it, remove Math.abs() in fifth line and you will get diffDays positive or negative so it would look like this:

var timeDiff = date2.getTime() - date1.getTime();
shershen
  • 9,875
  • 11
  • 39
  • 60