question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exporting Date-Times in Iso Format

See original GitHub issue

I want to export date/time values to JSON formatted as ISO 8601 values

My current script:

const XLSX = require('xlsx');
...
const file = XLSX.readFile(path,{cellDates:true, cellNF:false});
for (sheet in file.Sheets){
     //remove prerendered values, otherwise dateNF is ignored
     for (cellref in sheet){
         const c = sheet[cellref];
         if(c.t==="d"){
             delete c.w;
             delete c.z; 
         }
    }
   const format = "YYYY-MM-DD hh:mm:ss";
   //const format = "YYYY-MM-DDThh:mm:ss"; throws exception as it doesn't recognize T
   const data = XLSX.utils.sheet_to_json(sheet, {header: 1, dateNF:format});
   .....
}

The cells itself already contain the correct datetime inside the v(alue) attribute.

I suggest an option like XLSX.utils.sheet_to_json(sheet, {header: 1, ExportDatesAsISO:true});

Test data: datum.xlsx

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SCullmancommented, Apr 21, 2017

This script would work for me but feels just wrong:

const XLSX = require('xlsx');
...
const file = XLSX.readFile(path,{cellDates:true});
for (sheet in file.Sheets){
     for (cellref in sheet){
         const c = sheet[cellref];
         if(c.t==="d"){
             c.w = c.v;
         }
    }
   const data = XLSX.utils.sheet_to_json(sheet, {header: 1});
   .....
}
0reactions
SCullmancommented, Apr 22, 2017

Thank you, works perfect!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Given a DateTime object, how do I get an ISO 8601 date ...
FYI the formatexception's message is: "A UTC DateTime is being converted to text in a format that is only correct for local times....
Read more >
Standardize on ISO8601 for date and time exports in Briefcase ...
I believe that Central exports SubmissionDate as ISO 8601, and for any date / time / dateTime field, passes through whatever value was...
Read more >
How to Switch Microsoft Excel to ISO 8601 Standard Date ...
In today's video, I'm going to show you how to switch your Windows PC to the ISO 8601 standard date format. This will...
Read more >
How do I enter dates in ISO 8601 date format (YYYY-MM-DD ...
I tried to enter this date in ISO 8601 format (YYYY-MM-DD) in Excel 2010: 2012-04-08 , but Excel automatically converts the date format...
Read more >
The datetime string must match ISO 8601 format
Solved: I have a column with date and time in excel and there are empty values. I need to export the table into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found