11 December 2013

Adding days to a date in C#.net

using System;
 
namespace forgetCode
{
class Program
{
static void Main(string[] args)
{
 
Console.WriteLine("Enter year in the format dd-mm-yyyy");
DateTime dt = Convert.ToDateTime(Console.ReadLine());
 
Console.WriteLine("Enter the days to add :");
int days = Convert.ToInt32(Console.ReadLine());
 
DateTime newDate = dt.AddDays(days);
Console.WriteLine(newDate.ToShortDateString());


}
 
}
}

Output: 
Enter year in the format dd-mm-yyyy 
25-12-2012 
Enter the days to add : 
7 
01-01-2013

No comments:

Post a Comment