Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting yesterday's date 1

Status
Not open for further replies.

lfc77

Programmer
Aug 12, 2003
218
GB
How do I use DateTime to get for example, yesterdays date, or the date 5 days ago? I am using DateTime.Now.ToString() to get today's date, and I need to also find the date at certain intervals back from that.


Any assistance would be really appreciated.


Cheers,

lfc77
 
lfc77 Subtract a TimeSpan
Code:
TimeSpan ts = new TimeSpan(5,0,0,0);
DateTime dtToday = DateTime.Now;
DateTime dtToday5DaysAgo = new DateTime();
dtToday5DaysAgo = dtToday.Subtract(ts);
Console.WriteLine("today minus 5 days is " + dtToday5DaysAgo);
hth,
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top