Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
e.g

C#
string startdate = DateTime.Now.ToString("dd/MM/yyyy");

i.e= 14/03/2014

and want enddate as 14/04/2014....how to get?

startdate= " 14/03/2014";
enddate = "14/04/2014"

IN C#
Posted

Use DateTime.AddMonths():
using System;
public class Program
{
    public static void Main()	
    {
	    DateTime startDate = DateTime.Now;
		DateTime endDate = startDate.AddMonths(1);
		string format = "dd/MM/yyyy";
		Console.WriteLine(endDate.ToString(format));
    }
}
 
Share this answer
 
v2
Try this

C#
string endDate = Convert.ToDateTime(startdate).AddMonths(1).ToString();
 
Share this answer
 
write this code u will

string startdate = DateTime.Now.ToString("dd/MM/yyyy")
DateTime startdate1 = DateTime.Parse(startdate);
DateTime enddate = startdate1.AddMonths(1);
 
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