Adding days to a DateTime in C#

      No Comments on Adding days to a DateTime in C#

Add seven days to the current time.

DateTime start = DateTime.Now;
Console.WriteLine("Start date = " + start.ToString("dd/MM/yyyy hh:mm:ss"));
DateTime end = start.AddDays(7);
Console.WriteLine("End date = " + end.ToString("dd/MM/yyyy hh:mm:ss"));

Other methods for defining a DateTime object

DateTime start = DateTime.Parse("23/01/1984 01:02:03");
DateTime start = new DateTime(1984, 01, 23, 01, 02, 03);

Leave a Reply

Your email address will not be published. Required fields are marked *