Convert date column in excel to normal format (yyyy-mm-dd), current format is 41934
See original GitHub issueMy 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:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
还可以试试在读文件(
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
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.