Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends...i need to add months to date
for ex:the commencement date is 24-02-2015 and period of months is 15..then i want to add both and get result 24-05-2016
thank you....
Posted

Please do basic research before asking a question, you can easily google for this

http://stackoverflow.com/questions/5645058/how-to-add-months-to-a-date-in-javascript[^]
 
Share this answer
 
Comments
User-11630313 5-Sep-15 8:32am    
its not working good...
[no name] 5-Sep-15 8:40am    
What a precise comment... any Explanation available what the Problem is?
F-ES Sitecore 5-Sep-15 9:59am    
We're not mind-readers, we can't access your system. If you don't post your code no-one can help you.
User-11630313 7-Sep-15 2:35am    
sorry dude...my code is
<script type="text/javascript" language="javascript">
function datecalculate() {
var datefield = $find("<%= calCommenceDate.ClientID %>").get_selectedDate();
var prdduration = document.getElementById('<%= ddlPeriodCode.ClientID %>');
var duration =prdduration.options[prdduration.selectedIndex].text;
var mnths=duration.substring(0,2);
var res=new Date(new Date(datefield).setMonth(datefield.getMonth()+ parseInt(mnths)));
document.getElementById('<%= txtTerminateDate.ClientID %>').value=res;
}
</script>
this is works fine but the date format is not convenient for me...how to change the date format into dd-mm-yyyy..
thank you....
F-ES Sitecore 7-Sep-15 4:19am    
You'll have to construct the string in the format you desire, there are no decent date formatting functions in js

https://msdn.microsoft.com/library/ff743760(v=vs.94).aspx
JavaScript
var startdate = new Date(2015, 1, 24); //January = 0, February = 1, etc.
var endddate = new Date(startdate).add(15).month();


Source: Javascript: Add a month to a date[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900