im useless
im useless

Reputation: 7451

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.

Upvotes: 5

Views: 2574

Answers (4)

Vale
Vale

Reputation: 3298

Use AddDays() method:

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

Upvotes: 5

Richard Schneider
Richard Schneider

Reputation: 35477

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

var todayPlus10Days = DateTime.Today.AddDays(10);

Upvotes: 6

RvdK
RvdK

Reputation: 19790

Do you want to add days?

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

Note that you get a new DateTime back!

MSDN

Upvotes: 13

Will A
Will A

Reputation: 24988

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

Upvotes: 7

Related Questions