Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding days to a DateTime in C#

Is it possible to add dates in C#?

(DateTime.Today.ToLongDateString() + 10)

I tried this but it doesn't work.

like image 565
im useless Avatar asked May 24 '11 06:05

im useless


4 Answers

Do you want to add days?

DateTime newDate = DateTime.Today.AddDays(10);

Note that you get a new DateTime back!

MSDN

like image 179
RvdK Avatar answered Nov 19 '22 07:11

RvdK


Use DateTime.Today.AddDays(10) or any of the other AddXXX functions on DateTime.

like image 40
Will A Avatar answered Nov 19 '22 08:11

Will A


What is the unit of 10. If it is days; then

var todayPlus10Days = DateTime.Today.AddDays(10);
like image 23
Richard Schneider Avatar answered Nov 19 '22 08:11

Richard Schneider


Use AddDays() method:

DateTime dt = DateTime.Today;
dt = dt.AddDays(10);
like image 5
Vale Avatar answered Nov 19 '22 08:11

Vale