Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime 25 years back from today

Tags:

c#

datetime

in C# how do you calculate date 25 years ago from today?

like image 395
ren Avatar asked Sep 06 '11 14:09

ren


People also ask

What is today's DateTime?

The DateTime. Now property returns the current date and time, for example 2011-07-01 10:09.45310 . The DateTime. Today property returns the current date with the time compnents set to zero, for example 2011-07-01 00:00.00000 .

How accurate is DateTime now?

From MSDN you'll find that DateTime. Now has an approximate resolution of 10 milliseconds on all NT operating systems. The actual precision is hardware dependent. Better precision can be obtained using QueryPerformanceCounter .

How do I convert DateTime to time?

DateTime is an immutable type, so you can't change it. However, you can create a new DateTime instance based on your previous instance.

How can I get only the date from DateTime format?

ToString() − One more way to get the date from DateTime is using ToString() extension method. The advantage of using ToString() extension method is that we can specify the format of the date that we want to fetch. DateTime. Date − will also remove the time from the DateTime and provides us the Date only.


1 Answers

How about using AddYears:

DateTime then = DateTime.Today.AddYears(-25);
like image 154
Jon Skeet Avatar answered Oct 21 '22 21:10

Jon Skeet