System.DateTime remove (day/week/month)

Hello.. how can i remove x days or x weeks or x month from a DateTime.
I saw AddDays, AddMonths.. but i can't find how to substract a specific number of day/week or month from a date.

The only workaround a found is something like that:
System.DateTime sysDt = System.DateTime.Now()
sysDt = System.DateTime.FromOADate(Convert.ToDouble(sysDt.DayOfYear - 2));

I've not test well. and i want to know if it exist any easier way to do that.
Thanks for your help..
Alex..
LVL 10
jabcocoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GENTPCommented:
Just put AddDays(-1) or AddMonths(-1) to subtract one day or month.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jabcocoAuthor Commented:
Doh!
Thanks.
0
jabcocoAuthor Commented:
hum.. i will accept question later... i may have other question about remove/add week...
0
PoeticAudioCommented:
You can also use TimeSpan....

I don't have the IDE up right now (probably errors), but here's some code that might lead you in the right direction...

public DateTime SubtractDaysFromDate(DateTime dt, int numDays)
{
    TimeSpan span = new TimeSpan(numDays, 0, 0, 0, 0);
     
     DateTime date = dt.Subtract(span);
     return date;
}


usage:
DateTime dt = DateTime.Now;
dt = SubtractDaysFromDate(dt, 5);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.