DateTime Substract

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
 
M

mikeb

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))
 
C

CBN Media

Ouch, of course :)

Thank you both,

Cezar

mikeb said:
It's almost as simple:

DateTime.Now.AddDays( -4)

or

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top