2012-12-23 160 views

回答

49
MyNewDateValue = MyDateNow.AddDays(-MyDateInteger); 
3
MyNewDateValue = MyDateNow.AddDays(-120); 

MyNewDateValue = MyDateNow.AddDays(myVar); 
15

請看DateTime.AddDays方法

DateTime oneTwentyDaysAgo = DateTime.Today.AddDays(-120); 

或一般

DateTime nDaysAgo = DateTime.Today.AddDays(-N); 
// where N is the number of days 
1

試試這個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將幫助你從今天起增加或減去天。