Add a Time to a DateTime in C#
To add time to DateTime in C# you can use theDateTime.Add()
method which returns a new DateTime that adds the value of the specified TimeSpan to the value of this instance.Example
In below example we are going to add 10 days.using System;
public class Client
{
public static void Main()
{
DateTime date = DateTime.Now;
TimeSpan time = new TimeSpan(10, 0, 0, 0);
DateTime combined = date.Add(time);
Console.WriteLine(date);
Console.WriteLine(combined);
}
}
Output
3/1/2022 4:47:00 AM
3/11/2022 4:47:00 AM
3/11/2022 4:47:00 AM