question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

incorrect date format representation

See original GitHub issue

I working on excel date retrieving using ExcelDataReader. but it seem that i find issue with date column.

below is the image of excel data: error1

On retrieving using ExcelDataReader the date format is representing in number. error2

My code is :

 using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
                {
                    string fileExe = Path.GetExtension(FileUpload1.PostedFile.FileName);
                    IExcelDataReader excelReader;
                    if (fileExe == ".xls")
                    //1. Reading from a binary Excel file ('97-2003 format; *.xls)
                    {
                        excelReader = ExcelReaderFactory.CreateBinaryReader(stream, true);
                        //var excelReader = Excel.ExcelReaderFactory.CreateBinaryReader(inputStream, true);

                    }//...
                    //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
                    else
                    {
                        excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                    }
                    var excelDataSet = excelReader.AsDataSet(true);
                    //5. Data Reader methods
                    int j = 0;
                    while (excelReader.Read())
                    {
                        object[] array = new object[excelReader.FieldCount];
                        for (int i = 0; i < excelReader.FieldCount; i++)
                        {
                            if (j == 0)
                            {
                                dt.Columns.Add(i.ToString());
                            }
                            array[i] = excelReader.GetString(i);
                        }
                        j++;
                        dt.Rows.Add(array);
                    }
                    //6. Free resources (IExcelDataReader is IDisposable)
                    excelReader.Close();
                }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
nshanmugamcommented, Mar 22, 2017

Passing ‘true’ to the excelReader.AsDataSet method resolved the Date format issue for .xls files (into Dataset) . DataSet result = excelReader.AsDataSet(true);

0reactions
andersnmcommented, Jun 26, 2017

Looks like the dates are rendered as double because ConvertOaDates = false.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert an Incorrect Date Format into a Real Date in Excel
Change an incorrectly formatted/input date into the proper date format for Excel. This tutorial is specific to when someone inputs a "short" date...
Read more >
How to Fix Excel Dates That Won't Change Format
How to fix Excel dates that will not change format. Fix dates that end up in the wrong order when sorted. Use built-in...
Read more >
Java SimpleDateFormat.format() returns incorrect date ...
Even "yyyy-MM-dd'T'kk:mm:ss.SSS" returns incorrect values. Edit2 : I am using this code in Android App. It works on perfectly on emulator(API 23) ...
Read more >
Incorrect Date format
I would prefer the date in format (date) (month) (year) for eg. 15 August 2022. The month to always be alphabets and not...
Read more >
Excel Integration incorrect date format
I've never had issues integrating into excel, but I now the date format is coming in like this and I can't figure out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found