Converts an Excel serial date to DateTime
/// <summary>
/// converts an Excel serial date to DateTime
/// </summary>
/// <param name="nSerialDate"></param>
/// <returns></returns>
static DateTime ExcelSerialToDateTime(int nSerialDate)
{
return (new DateTime(1900, 1, 1)).AddDays(nSerialDate - 2);
}
===Or====
static DateTime ExcelSerialDateToDT(int nSerialDate)
{
int l = nSerialDate + 68569 + 2415019;
int n = ((4 * l) / 146097);
l = l - ((146097 * n + 3) / 4);
int i = ((4000 * (l + 1)) / 1461001);
l = l - ((1461 * i) / 4) + 31;
int j = ((80 * l) / 2447);
int nDay = l - ((2447 * j) / 80);
l = (j / 11);
int nMonth = j + 2 - (12 * l);
int nYear = 100 * (n - 49) + i + l;
return DateTime.Parse(nMonth + "/" + nDay + "/" + nYear);
}
No comments:
Post a Comment