5

Is it possible to add dates in C#?

(DateTime.Today.ToLongDateString() + 10)

I tried this but it doesn't work.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
im useless
  • 7,151
  • 7
  • 35
  • 49

4 Answers4

13

Do you want to add days?

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

Note that you get a new DateTime back!

MSDN

RvdK
  • 19,580
  • 4
  • 64
  • 107
7

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

Will A
  • 24,780
  • 5
  • 50
  • 61
6

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

var todayPlus10Days = DateTime.Today.AddDays(10);
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
5

Use AddDays() method:

DateTime dt = DateTime.Today;
dt = dt.AddDays(10);
Vale
  • 3,258
  • 2
  • 27
  • 43