This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Get Number of Months From two Dates using Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Get Number of Months From two Dates using Javascript" Watch "Get Number of Months From two Dates using Javascript" New topic
Author

Get Number of Months From two Dates using Javascript

Sreenivas Reddy Tatikunta
Greenhorn

Joined: Aug 23, 2011
Posts: 24

Hi All,


I have following dates in javascript,

var date1 = 05-30-2011
var date2= 08-23-2011(Current Date)

It should compare both dates and return number months. This example result is 2 months 23 days (Here days not required only should return exact months). Using javascript.

If anyone have idea could you please help me...


Thanks & Regards
Sreenivas Reddy.T
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Looks like you need:

  • new Date()
  • getFullYear()
  • getMonth()


  • Eric
     
    jQuery in Action, 2nd edition
     
    subject: Get Number of Months From two Dates using Javascript
     
    Similar Threads
    Can anyone send me the code to calculate the years/months/days between the tow dates.
    How to convert Number of Days to MM and DD
    resultset is not working properly
    Date
    Problem with javascript dates