Read DateTime data from Excel file using C#

Excel files are very tricky to deal with, sometimes it returns double value, sometimes just plain string.

The example processes values read by EPPlus, might be useful in other situations, too.

public DateTime GetDate(object valFromExcel)
{
if(valFromExcel is DateTime) return valFromExcel;
if(valFromExcel is double) return DateTime.FromOADate((double)valFromExcel);
return Convert.ToDateTime(valFromExcel);
}

Leave a Reply

Your email address will not be published. Required fields are marked *