Possible Duplicate:
c#: whats the easiest way to subtract time?
I want
MyNewDateValue = MyDateNow - MyDateInteger;
Example Today is the 22nd of December 2012
If MyDateIneger value is 120, MyNewDateValue, will return the datetime 120 days ago.
MyNewDateValue = MyDateNow.AddDays(-MyDateInteger);
Please look into DateTime.AddDays
method
DateTime oneTwentyDaysAgo = DateTime.Today.AddDays(-120);
or in general
DateTime nDaysAgo = DateTime.Today.AddDays(-N);
// where N is the number of days
MyNewDateValue = MyDateNow.AddDays(-120);
or
MyNewDateValue = MyDateNow.AddDays(myVar);
Try this frnd
DateTime dt = new DateTime();
dt = DateTime.Now;
DateTime newdt = new DateTime();
TimeSpan tim = new TimeSpan(120,0,0,0,0);
newdt = dt.Add(tim);
MessageBox.Show(newdt.ToString());
ADD.timespan will help you to add or subtract days from today.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With