1

I am having a problem with parsing excel content to datetime type.

In my country, there are just two cultureinfo to use: "vi-VN" (dd/MM/yyyy) and "us-US" (MM/dd/yyyy).

For some cases I test, both DateTime.Parse with cultureinfo above throwing error "String is not recognized as a valid datetime".

I want to use DateTime.ParseExact instead of above approach. In order to do this, I must get a string like "12/31/2018". But when I use Epplus, it reads the content of the cell as a number 43465. This way, I cannot parse use DateTime.ParseExact.

Any here know how to read the excel as you see on the screen ?

Thank you.

user3819222
  • 127
  • 8
  • 1
    Why don't your convert the int to datetime with `DateTime.FromOADate()` - see this for futher info https://stackoverflow.com/questions/727466/how-do-i-convert-an-excel-serial-date-number-to-a-net-datetime – Rand Random Nov 12 '18 at 10:25
  • 1
    Excel stores "Dates" as "number of Day since X". While also having a broken Leap year detection (1900 is incorrectly considered a Leap year). And hte mac version has the "Day X" offset by 4 years too. – Christopher Nov 12 '18 at 10:26
  • I never heard this formula. Thank you so much :D – user3819222 Nov 14 '18 at 16:08

1 Answers1

2

DateTime.FromOADate(Double) Method

var dateTime = DateTime.FromOADate(43465);
Alex
  • 66
  • 3