How to add days to date in c#


To add a day to existed date, we can use Adddays inbuilt function in C#. it associated with the date time data type.  Call the function after dot and pass number of the days as a parameter in the add days function. Following is the code samples to understand the use of add days function. In following olddate name Date time variable is created and current date is assign to it. Then 12 days is added to current date time and new date time after adding assign to new_datetime variable.

 C# |  copy code |? 
DateTime olddate=DateTime.Now;
DateTime new_datetime = olddate.AddDays(12); 

Leave a Comment

Your email address will not be published.