DateTime Substract

  • Thread starter Thread starter CBN Media
  • Start date Start date
C

CBN Media

Hi,

I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a
param a TimeSpan.

Am I looking at the wrong method here? It should be as simple as AddDays,
right?!

Thanks,
Cezar
 
CBN said:
Hi,

I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a
param a TimeSpan.

Am I looking at the wrong method here? It should be as simple as AddDays,
right?!

It's almost as simple:

DateTime.Now.AddDays( -4)

or

DateTime.Now.Subtract( new TimeSpan( 4, 0, 0, 0))
 
Back
Top