try this out:
public class YourClass {
private static readonly DateTime march1st1900 = new DateTime(1900, 03, 01);
private static readonly DateTime december31st1899 = new DateTime(1899, 12, 31);
private static readonly DateTime january1st1904 = new DateTime(1904, 01, 01);
private static readonly TimeSpan date1904adjustment = new TimeSpan(4 * 365 + 2, 0, 0, 0, 0);
private static readonly TimeSpan before1stMarchAdjustment = new TimeSpan(1, 0, 0, 0);
/// <summary>
/// Converts the Excel date to the Date which we can read.
/// </summary>
/// <param name="excelDate"></param>
/// <returns></returns>
DateTime ConvertExcelDateToDate(object excelDate)
{
DateTime date = (DateTime)excelDate;
if (date1904)
return date + date1904adjustment;
if (date < march1st1900)
return date + before1stMarchAdjustment;
return date;
}
/// <summary>
/// Converts a Date to the Excel date representation
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
object ConvertDateToExcelDate(DateTime date)
{
if (date1904)
{
if (date >= january1st1904)
return date - date1904adjustment;
else
return date.ToString(DateTime.Now.ToString("MM/dd/yyyy"));
}
if (date >= march1st1900)
return date;
if (date < march1st1900 && date > december31st1899)
return date - before1stMarchAdjustment;
return date.ToString(DateTime.Now.ToString("MM/dd/yyyy"));
}
} // end class
Usage:
object excelDate = myRange.get_Value(Type.Missing);
DateTime goodDate = ConvertExcelDateToDate(excelDate);
Hope this helps..the usage code just retrieves the range value and passes it to the Conversion method