Subtract 1 year from datetime

Phil picture Phil · Apr 30, 2010 · Viewed 31.6k times · Source

I have seen a lot of info on how to subtract one datetime from the other and how to add years on to a datetime. but the following is giving me a headache....

When a user inserts a record a hidden field called subdate with a value of datetime.now is added to the db.

I then need to have an 'old records' page that lists all the entries that are over 1 year old and was hoping to use something (but using subtract method) similar to;

(DateTime.Now.AddYears(1))

but there is no SubtractYears available? Why?

Please can you let me know how I achieve the same result?

Answer

Kobi picture Kobi · Apr 30, 2010
DateTime.Now.AddYears(-1)

From the documentation:

A number of years. The value parameter can be negative or positive.