I have one weird issue reading datetime
value from CSV file. When I read the file programmically, it reads the value of datetime
column as shown in below image.
As you can see in below image, it is just like some number eg 57.07.7
(NOTE: I can't change the cell format of the CSV file)
You can download file from here:
BUT
same file, if you open in notepad
or notepad
, it gives proper datetime
value as shown in below image
When I read as below, it is giving me result as first image,
const xlsx = require("xlsx");
const result = // read file here and get buffer data;
const file = xlsx.read(result);
const sheetNames = file.SheetNames;
const totalSheets = sheetNames.length;
// Loop through sheets
for (let i = 0; i < totalSheets; i ) {
// Convert to json using xlsx
let tempData = xlsx.utils.sheet_to_json(file.Sheets[sheetNames[i]]);
parsedData.push(...tempData);
}
If I console.log(parseData)
, it shows some number
not date(as string)
.
What's wrong? How can I read proper date ?
CodePudding user response:
Try setting cellDates:true
to parse dates as type d
try this:
const file = xlsx.read(result, {cellDates:true});
..or maybe use a csv parser..