Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one textbox in which i am getting one datetime value for example '7/27/2015 12:00:00 AM', and I have one dropdown list control with the list of Monthly,Quarterly,HalfYearly,Yearly. So how to add only months on that date by changing the dropdown periods?

I tried like below but getting extra months and year not changing if month get above 12.

What I have tried:

var d = new Date($("#<%=txtActDate.ClientID%>").val());
            var curr_date = d.getDate();                            
            if (packPeriod == 'Monthly') {

                 var curr_month = d.getMonth() + 1;
            var curr_year = d.getFullYear();
            var dates = curr_date + "/" + curr_month + "/" + curr_year;
              alert(dates );
            }
            else if (packPeriod == 'Quarterly') {
              var curr_month = d.getMonth() + 3;
            var curr_year = d.getFullYear();
            var dates = curr_date + "/" + curr_month + "/" + curr_year;
                alert(dates );
            }
            else if (packPeriod == 'HalfYearly') {
               var curr_month = d.getMonth() + 6;
            var curr_year = d.getFullYear();
            var dates = curr_date + "/" + curr_month + "/" + curr_year;
                alert(dates );
            }
            else if (packPeriod == 'Yearly') {
              var curr_month = d.getMonth() + 12;
            var curr_year = d.getFullYear();
            var dates = curr_date + "/" + curr_month + "/" + curr_year;
                alert(dates );
            }
Posted
Updated 12-Mar-16 4:56am

1 solution

Have a look at the answer from bmpasini on this post - Javascript function to add X months to a date - Stack Overflow[^]

NB - the most popular (and the accepted) solution doesn't actually work properly - use the one from bmpasini
 
Share this answer
 

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