Nirmal
Nirmal

Reputation:

datetime subtract .net

i want to get datetime for 2days before. i.e) how to subtract 2 days from datetime.now

Upvotes: 4

Views: 2918

Answers (3)

DocMax
DocMax

Reputation: 12164

I think you are just looking for:

DateTime.Now.AddDays(-2);

Upvotes: 27

Inisheer
Inisheer

Reputation: 20794

Yet another solution:

DateTime twoDays = DateTime.Now.Subtract(new TimeSpan(2,0,0,0));

Upvotes: 1

Joachim Kerschbaumer
Joachim Kerschbaumer

Reputation: 9891

or try:

DateTime.Now.Subtract(TimeSpan.FromDays(2));

Upvotes: 9

Related Questions