Arif YILMAZ
Arif YILMAZ

Reputation: 5876

How to import DateTime cell from Excel in C# properly

I am trying to import Excel file's data into my ERP with a custom C# application. But, I am having a problem with Date type cells. Depends on the regional settings of computers, Date type cells cannot be converted to DateTime in C#, I am always having a problem with this Date from Excels when users use different computers.

If computer's regional settings is U.S.

11-25-2016

If computer's regional settings is Turkish

25-11-2016

How can I do the proper conversion?

Upvotes: 1

Views: 1656

Answers (2)

Sebastian Siemens
Sebastian Siemens

Reputation: 2421

You may try the following:

System.Globalization.CultureInfo cultureinfo = System.Globalization.CultureInfo.CurrentCulture;
DateTime dt = DateTime.Parse(date, cultureinfo);

Upvotes: 1

Penman
Penman

Reputation: 173

Convert the date to C# using the following code:

DateTime conv = DateTime.FromOADate(excelDate);

Refer this answer: Reading Datetime value From Excel sheet

Upvotes: 1

Related Questions