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.

Date format issue dd/mm/yyyy

See original GitHub issue

We are using sheetjs for exporting report which having date coulmns in dd/mm/yyyy format. The exported file converts the date to to mm/dd/yyyy format for those date are less than 13 and other dates are exported as desired. We need to export file with dd/mm/yyyy format itself

How to fix this issue? Or what is the way to disable autoformatting of date column and consider it as string itself?

Sample Code as follows:

<table id="table">
<tr>
  <td>1</td>
  <td>05/04/2021</td>
  <td>Fifth April, Monday</td>
</tr>
<tr>
  <td>2</td>
  <td>06/04/2021</td>
  <td>Sixth April, Monday</td>
</tr>
<tr>
  <td>3</td>
  <td>11/04/2021</td>
  <td>Eleventh April, Sunday</td>
</tr>
<tr>
  <td>4</td>
  <td>12/04/2021</td>
  <td>Twelvth April, Monday</td>
</tr>
<tr>
  <td>5</td>
  <td>13/04/2021</td>
  <td>Thirtheenth April, Monday</td>
</tr>
<tr>
  <td>6</td>
  <td>14/04/2021</td>
  <td>Fourtheenth April, Monday</td>
</tr>
</table>
 var wb = XLSX.utils.table_to_book(document.getElementById('table'));
        XLSX.writeFile(wb, "sample.xlsx");

Sample JSFiddle is here

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
SheetJSDevcommented, Sep 16, 2021

There are a few issues here:

@mpsbhat is asking about parsing of ambiguous dates. It is unclear whether “2/1/21” represents “January 02” or “February 01”. There are two workarounds:

A) If you want to bypass value parsing entirely, pass raw: true to table_to_book:

 var wb = XLSX.utils.table_to_book(document.getElementById('table'));

B) If you are generating the HTML table, you can add t, v, z attributes to the TD element. If the DOM walker sees those attributes, it will use them in lieu of parsing the text. For dates you would set t="d" and set v to the ISO8601 string of the date you want.

@nivb52 If you have full control over what value you pass, you can actually pass cell objects like {t:"n", v:45544, z:"m/d/yy"} instead of the raw date codes. The writers will use the specified number format and Excel will treat them like dates.

@Triyank passing raw: true will disable date parsing

0reactions
Triyankcommented, Apr 20, 2021

i have some issue, is there any way someone can help? i am uploading an excel and xlsx.read is converting date in my excel In Date(); format of JS but I dont want that i want this has to be treated as string. no conversion in Date object. any suggestions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cant set date to DD/MM/YYYY only DD-MM-YYYY available
I need to set a date to date format DD/MM/YYYY (forward slash) but my Excel 2016 only shows this date format with a...
Read more >
Date format issue - dd/mm/yyyy | MrExcel Message Board
I change all date values to dd/mm/yyyy format. But every time another user opens it, the format becomes d/m/yyyy. I prefer dd/mm/yyyy so...
Read more >
Excel format text as date (dd mm yyyy format ) #shorts - YouTube
Learn how to fix dates that are in the wrong format. Follow this video to see how to change the date format from...
Read more >
Can no longer format date as dd/mm/yyyy in Excel (Office 365)
I have just noticed that appear to no longer be able to format the date as dd/mm/yyyy in Excel (Office 365)
Read more >
Date Format "dd/MM/yyyy" Goes Wrong While Writing in Excel
Also what I realized, it only does this error while there is 01 in the date. So today is 02/01/2020 according to my...
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