An annoying little 'feature' of Excel is that it stores dates in a strange format
I stole the logic and from Code Project and wrote some code that will give you a DateTime variable if you feed it a Excel serial integer (number of days after 2/29/1900). Strangely enough, DateTime.Parse("2/29/1900"); throws an error, so the simple solution I thought of: DateTime.Parse("2/29/1900").AddDays(excelInteger); does not work. But this does:
public 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);
}
As long as your date isn't within 60 days of 2/29/1900, this will work perfectly (don't ask why those are screwed up
).