Monday, 18 May 2009

Converting Excel date format into System.DateTime



public static DateTime ConvertToDateTime(double excelDate)
{
if (excelDate < 1)
{
throw new ArgumentException("Excel dates cannot be smaller than 0.");
}
DateTime dateOfReference = new DateTime(1900, 1, 1);
if (excelDate > 60d)
{
excelDate = excelDate - 2;
}
else
{
excelDate = excelDate - 1;
}
return dateOfReference.AddDays(excelDate);
}


http://www.clear-lines.com/blog/post/Converting-Excel-date-format-to-SystemDateTime.aspx

No comments: