sheetjs
sheetjs copied to clipboard
Excel is not storing exact date. Preserving last day
Hi, I am using SheetJs and trying to store date into excel sheet. I noticed the date records are storing incorrectly, Ex - when i try to store 04-05-2022 , it is storing 04-04-2022. It is missing 1 day and storing previous date. Am using latest version 0.18.5 . Please advise
Can you share an example file and your system timezone?
This is an old issue...
Is not one day left, ist just a few seconds left For example 20/12/2021 00:00:00 is export as 19/12/2021 23:59:12
My timezone is -3
a simple example to reproduce:
const exportData = [
{ date: new Date('2021/12/20 00:00:00'), name: 'Peter' },
{ date: new Date('2021/12/30 18:30:00'), name: 'Jhon' },
]
const wb: XLSX.WorkBook = XLSX.utils.book_new();
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(exportData, { dateNF: 'dd/mm/yyyy HH:mm:ss' });
ws['!cols'] = [{ wch: 30 }, { wch: 30 }];
XLSX.utils.book_append_sheet(wb, ws, 'Data');
XLSX.writeFile(wb, 'data.xlsx');
| date | name |
|---|---|
| 19/12/2021 23:59:12 | Peter |
| 30/12/2021 18:29:12 | Jhon |
Atlantic/Azores h/t @ruitalia . The timezone had fractional offset -1:42:40 in 1900
I'm also using version 0.18.5 and see the same issue in India Standard Time zone. It looks like 10 seconds is being subtracted off of the time.
Date in Excel File: 7/5/2023
Result after XLSX.read: { "t": "d", "v": "2023-07-04T18:29:50.000Z", "z": "m/d/yy" }