Convert time-formatted column in excel to C# DateTime
As FrankPI said, use DateTime.FromOADate()
. You would use this function with the raw data from an Excel cell - there is no need to parse the format.
Excel encodes its dates and times in a double. The integral portion represents the days after January 1, 1900. The fraction part represents the time since midnight of the day referenced. For example:
1.5 is January 1, 1900 @ Noon
and
41507.25 = August 21, 2013 @ 6:00 am
Refer to the MSDN docs on this function for more information:
http://msdn.microsoft.com/en-us/library/system.datetime.fromoadate.aspx
Convert String to datetime [Wed Mar 01, 2017 6:00 AM] this format in c#
You can specify custom format:
DateTime finaldate = DateTime.ParseExact(mydate, "ddd MMM dd, yyyy h:mm tt", CultureInfo.InvariantCulture);
Date Format - C# - Conversion
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")));
Excel treating date column as general when exporting to Excel using C#
To Set text as DateTime
format in epplus you need to set the format type for a cells
EG:
1) For simple short date Pattern
workSheet.Cells[row, 3].Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
2) If you want specific format like datetime with time,hour etc then
workSheet.Column(dateColIndex).Style.Numberformat.Format = "mm/dd/yyyy hh:mm:ss AM/PM";
Related Topics
C# - How to Loop Through a Table to Update Each Row MySQL
How to Get Cookies Info Inside of a Cookiecontainer (All of Them, Not for a Specific Domain)
Display Label Text With Line Breaks in C#
C# Double - Tostring() Formatting With Two Decimal Places But No Rounding
C# Windows Form Application for Employee Management
How to Print the Elements With Text Value That Contains in a List Selenium C#
Ssh.Net Sftp Get a List of Directories and Files Recursively
Asp Core Webapi Test File Upload Using Postman
Update Value in Datatable from Another Datatable
Using Newtonsoft to Deserialize a Date Stamp That Might Consist Only of a Year
How to Display Values Only Upto 2 Decimal Places
C# Percentage Calculation Explanation
How to Get the List of Properties of a Class
How to Determine If .Net Core Is Installed
How to Efficiently Remove a Query String by Key from a Url