Reputation: 1909
I have a start date(mm/dd/yyyy) in javascript... I need to find out the exact date after 6th month
e.g.
Given: var fromDate = new Date("01/17/2012");
Expected : 07/17/2012
How to do so in javascript?
Upvotes: 0
Views: 1145
Reputation: 7371
It's very simple using Javascripts getMonth() method
var fromDate = new Date('01/17/2012');
var toDate = new Date(new Date(fromDate).setMonth(fromDate.getMonth() + 6));
EDIT
Here is a prototyped method for formatting the date to mm/dd/yyyy
var formatted = toDate.defaultView()
Date.prototype.defaultView=function(){
var dd=this.getDate();
if(dd<10)dd='0'+dd;
var mm=this.getMonth()+1;
if(mm<10)mm='0'+mm;
var yyyy=this.getFullYear();
return String(mm+"\/"+dd+"\/"+yyyy)
}
Upvotes: 2