图片 1

c#(asp.net) 计算两个日期之间相隔天数

图片 1

1、
DateTime
t1 = Convert.ToDateTime(“2006-1-6”); 
DateTime
t2 = Convert.ToDateTime(“2006-1-16”); 
int
day=Math.Abs(((TimeSpan)(t1 – t2)).Days); 

2、
datediff(day,date1,date2)

3、 
DateTime
oldDate = new DateTime(2002,7,15); 
DateTime
newDate = DateTime.Now; 
//
Difference in days, hours, and minutes. 
TimeSpan
ts = newDate – oldDate; 
//
Difference in days. 
int
differenceInDays = ts.Days; 
Console.WriteLine(“Difference
in days: {0} “, differenceInDays); 

发表评论

电子邮件地址不会被公开。 必填项已用*标注