Reputation: 190
I extracted data from a Database to Excel, the date columns are expressed in this format.
38876,588587963
I am now trying to read this file in C# and convert dates into DateTime format. Can someone enlighten me on this date format.
When i try to create a DateTime object the software throw an error.
DateTime dt = new DateTime("38876,588587963");
Upvotes: 0
Views: 137
Reputation: 2674
You can convert it into a DateTime
by using the FromOADate
method in DateTime
. However, that method accepts a double which doesn't work with the current formatting, parse it as a double
and set the culture settings like this:
string output = "38876,588587963";
DateTime dt = DateTime.FromOADate(double.Parse(output, CultureInfo.CurrentCulture));
Or if you know the culture is going to always be fr-CA
you can do:
DateTime dt = DateTime.FromOADate(double.Parse(output, CultureInfo.CreateSpecificCulture("fr-CA")));
Upvotes: 3