0

I want to get the number of months between two dates with JavaScript, but if the number of days greater than 30 days or greater than 1 month then it directly return me two months.

For example if my from date is 17/01/2011 and to date is 20/02/2011 then my function returns two months because then days between two days exceeds one month.

Hope you all understand.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Pravin
  • 95
  • 18
  • But if the first date is 17/01/2011 and the next one is 21/07/2012 should it still return 2 months? Or do you just want it to round up the number of months? – user535617 Jan 17 '11 at 16:06
  • @user535617 No at this time it returns 7 months instead of 6 months because the days are exceed then 6 months exactly. means round up the number of months – Pravin Jan 17 '11 at 16:16

1 Answers1

0

I recommend Mootools Date.diff. If you're tied to jQuery, you could instead refer to this post on Stack Overflow.

Community
  • 1
  • 1
Kyle Wild
  • 8,845
  • 2
  • 36
  • 36