Formatting dates in XLSX.utils.sheet_to_json makes date lose 1 day #3019
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#3019
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello !
I know this is a topic that has been mentionned multiple times but I can't seem to find a fix.
Here's the code :
const workbook = XLSX.read(data, {type: 'array', cellDates: true, cellText: false, cellNF: true});
const firstSheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[firstSheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, {raw: false, dateNF: 'd"/"m"/"yyyy'});
Everytime I try to run this code, I get the right date format, but the date loses one day.

For example, in the original XLSX file:
But once I print the jsonData, I get:


Any solution to this ?
I'm using the 0.20.0 version's standalone file on Chrome (that was supposed to fix this issue):
https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js
Can you share the file?
If you're talking about the XLSX file, here's the one I did the tests with.
Assuming you are talking about column E, can you display the raw date before generating the final result?
Also, since you are passing
cellNF: true
, the default date format will be added to cells. You need to wipe the number format for date cells after reading and before generating the data:I don't really need the cellNF: true, it was just for testing purpose. If I remove it, will I still need to use the second code snippet that you sent me ?

Here's the raw date before generating the final result using the first code snippet (without cellNF: true):
Same thing but with cellNF: true

We are unable to reproduce the issue locally. Can you also share your browser locale? Run the following in the console
NodeJS
Sample script:
Save that script to
i3019.js
, copy your template to the same directory, runnpm i --save https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz
, then runnode i3019.js
.This prints the dates using the
m/d/yy
format:Modified Date Formats
If you add that loop:
you will see the dates in the format you specified:
Browser
Save the following to
index.html
:Copy the
Template_upload_passagers.xlsx
file into the same folder, then start a local web server:It will display a URL (typically http://localhost:8080). Open that URL in a web browser and check the console. Chrome 117 shows:
Modified Date Formats
If you add that loop:
The console will show the modified date formats:
Hi, here's the result of my browser locale:
Europe/Paris
I tried using your code, and I still get the issue.
Here's the code:
To quickly explain the rest of the code, I'm trying to convert an xlsx file to a csv and upload it into a database (I'm building a plugin for a No-Code application on the Bubble.io platform, hence the properties.xlsx_file, context.uploadContent and instance.publishState. Don't mind those.)

Running the above code and looking into the browser console gives me the following:
Could it be because of my browser locale ?
Europe/Paris
is currently in Central European Standard Time which is UTC+2. Pass the optionUTC: true
tosheet_to_json
to force the correct interpretation.https://docs.sheetjs.com/docs/csf/features/dates#utc-option more details.
We will revisit the default option for that setting in the future.
Reflecting on this a bit, it probably makes sense to force
UTC: true
whenraw: false
is set.Awesome ! My dates don't lose one day anymore ! Thank you very much for all the help that you've provided :)
UTC: true
andraw: false
still stealing a few seconds to the date@ruitalia can you share your current timezone and a small example?
I'm in Atlantic/Azores UTC-1 timezone.
I realize now that in 0.20.0 version the
raw: false
is working nice, but withUTC: true
the bug remains.