sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

Excel is not storing exact date. Preserving last day

Open uchakula13 opened this issue 3 years ago • 4 comments

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

uchakula13 avatar Apr 05 '22 16:04 uchakula13

Can you share an example file and your system timezone?

reviewher avatar Apr 06 '22 03:04 reviewher

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

chacabuk avatar Apr 08 '22 18:04 chacabuk

Atlantic/Azores h/t @ruitalia . The timezone had fractional offset -1:42:40 in 1900

SheetJSDev avatar Sep 09 '22 21:09 SheetJSDev

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" }

mrichard95 avatar Jul 21 '23 15:07 mrichard95