Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have No. of months, start date and end date in my web page.

No. of Months
Start Date
End Date

when i give no of months 10 and start date 18/5/2015, then end date automatically calculate to +10 months (i.e 18/3/2016)
Posted
Comments
Sinisa Hajnal 18-May-15 2:28am    
So, what is the problem? You have SQL server tag - do you need to calculate in SQL or in code behind or client side (javascript)?

Why can't you just use one of many examples easily found on the net?

Try:
C#
DateTime dt;
int months;
if (DateTime.TryParse(date text), out dt) && int.TryParse(monthText, out months))
   {
   dt = dt. AddMonths(months);
   ...
   }
 
Share this answer
 
Simple example :

Input Parameters :
Input Date - 18/5/2015 DD/MM/YYYY
No. of months - 10


C#
DateTime odt = new DateTime(2015, 5, 18);


Console.Write(odt+ "\n");
            
Console.WriteLine(odt.AddMonths(10));
 
Share this answer
 
C#
int noofmonths = 1;
          //here you can pass your date as you want
          DateTime fromdate = new DateTime(2015, 05, 18);
          DateTime todate = fromdate.AddMonths(noofmonths);
 
Share this answer
 
DateTime date = DateTime.Now;
Console.WriteLine(date.AddMonths(10));
Console.ReadKey();
 
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