November 14, 2007

Converting Excel's DateTime serial to Windows DateTime



This little snippet here will allow you to convert excel encoded date to standard Windows DateTime.

public static DateTime ExcelDateConverter(int excelDateSerial)
{
if (excelDateSerial <>
{
excelDateSerial++;
}
return new DateTime((excelDateSerial + 693593) * (10000000L * 24 * 3600));

}


Back to Home

3 comments:

  1. Why dont u use DateTime.FromOADate(double d) (standard 1.1.4 framework)??

    It works perfectly when u have a datetime column in excel and then convert it to text. It will result in a int number. This method convert it to a datetime again.

    ReplyDelete
  2. Dear Anonymous,
    can you explain your method please...

    ReplyDelete
  3. @fatih he's right..
    you can do something like this:
    Dim d As DateTime = DateTime.FromOADate(numbertoconvert)
    and it works perfectly!

    ReplyDelete

Note: Only a member of this blog may post a comment.