-1

I have 2 date values, one for the current date, and one for the last day of the month.

I am trying to find the remaining days left in the current month (end of the month - current date)

The syntax for my code is a bit confusing when it comes down to finding the difference for these 2 dates.

Here is my code:

function findDays() {
  var now = new Date();
  var date = now.getDate();
  console.log(date);
  return new Date(now.getFullYear(), now.getMonth()+1, 0).getDate();
}

console.log(findDays() - (new Date(2016, 0, 1)).getDate());
Khan
  • 223
  • 2
  • 3
  • 11
  • Possible duplicate of [Get difference between 2 dates in javascript?](http://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript) – eltonkamami Jul 19 '16 at 20:43
  • Where are those two objects? As far as I understood you wanted to pass in 2 objects and see how many days left? Is this correct? – Coding Duchess Jul 19 '16 at 20:43
  • Yes I think I have worded it a bit confusing. I am trying to find how many days are left in the month. – Khan Jul 19 '16 at 20:48

1 Answers1

0

I think you mean to get this:

function findDays() {
  var now = new Date();
  var date = now.getDate();
  var last=new Date(now.getFullYear(), now.getMonth()+1, 0).getDate();
  return last-date;
}
Coding Duchess
  • 6,445
  • 20
  • 113
  • 209