Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get one year back from current date

Tags:

c#

I want to get exactly one year back from the current date (which I am passing) in .Net. Can anyone provide me a function or code that will perform this?

like image 475
Mahendra Avatar asked Jul 19 '10 11:07

Mahendra


People also ask

How do you add one year to a date in react JS?

To add years to a date: Use the getFullYear() method to get the year of the specific date. Use the setFullYear() method to set the year for the date. The setFullYear method takes a number representing the year as a parameter and sets the value for the date.


2 Answers

You can use the AddYears() method:

DateTime.Now.AddYears( -1 ); 
like image 155
tanascius Avatar answered Oct 15 '22 01:10

tanascius


Try DateTime.AddYears(-1);

like image 21
DevDemon Avatar answered Oct 15 '22 02:10

DevDemon