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.

Convert date column in excel to normal format (yyyy-mm-dd), current format is 41934

See original GitHub issue

My date column shows numbers like 45123 instead of showing yyyy-mm-dd, how can i read this excel file and generate a json with a correct date format.

thats my function to read xlsx:

const xlsxtojson = (path, headers) => {
    const workbook = XLSX.readFile(path);
    let jsonData = [];
    jsonData = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { header: headers, range: 1 });
    return jsonData;
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
demon-zhonglincommented, Nov 11, 2020

还可以试试在读文件(XLSX.read)的时候进行一些设置: XLSX.read(data, { type: 'binary', cellDates: true })

cellDates: 将日期存储为类型d(默认为n)(类型详情: https://github.com/SheetJS/sheetjs#data-types) 设置完后,重新读取文件时,你会发现此时值为 js 的 Date 对象

=================================== You can try this when reading files(XLSX.read): XLSX.read(data, { type: 'binary', cellDates: true })

cellDates: Store dates as type d (default is n) (Data Types: https://github.com/SheetJS/sheetjs#data-types)

You will find that the current value is a js Date object

3reactions
cooljeffrocommented, Nov 12, 2020

The format is the number of days since Jan 1, 1900. However, Excel incorrectly counts 1900 as a leap year.

To get the date using moment: moment('1900-01-01').add(45123 - 2, 'days').format('YYYY-MM-DD').

This will work for dates after 1900-02-28.

Read more comments on GitHub >

github_iconTop Results From Across the Web

excel-convert a date column form mm/dd/yyyy to yyyymmdd
In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want...
Read more >
How to convert yyyymmdd to normal date format in Excel?
Convert yyyymmdd to normal date format with Text To Column functiona · 1. Select the data range that you want to convert. ·...
Read more >
How to change Excel date format and create custom formatting
The easiest way to change date format in Excel based on how another language displays dates is as follows: Select the column of...
Read more >
Convert YYYYMMDD to DD/MM/YYYY - EXCEL EXERCISE
But you can convert YYYYMMDD date, or any other date format, to your local date format with the tool Text to Columns. Normally...
Read more >
6 Ways to Fix Dates Formatted as Text in Excel
Excel Convert text dates with the VALUE function ... number for your date, you will then need to format the cell with a...
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