Thứ Tư, 8 tháng 10, 2014

Tính số ngày giữa 2 ngày tháng cho trước C#

DateTime now = DateTime.Now;
DateTime then = new DateTime (1, 1, 2005);
TimeSpan diff = now - then;
int days = diff.Days;
 Hoặc.

private int DateDiffInDays(DateTime fromDate, DateTime toDate)
{
return toDate.Subtract(fromDate).Days;
}

Không có nhận xét nào: