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.

How to write Date into an excel file in a specific format

See original GitHub issue

I am trying to build an excel sheet which has date in a specific column. I am doing something like this: sheet.getCell('A6').value(new Date());

when I generate the excel sheet, this gives me 4/9/2018

I would like it to display this instead: 4/9/2018 12:26:00 PM

Issue Analytics

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

github_iconTop GitHub Comments

12reactions
guyonrochecommented, Apr 19, 2018

@pmaiya - if you want to control how the date appears when loaded in Excel, then you need to use cell formatting:

sheet.getCell('A6').value = new Date();
sheet.getCell('A6').numFmt = 'm/d/yyyy\\ h:mm:ss\\ AM/PM'; // I think this is right ;-)
5reactions
nabeelz6commented, Aug 1, 2018

@guyonroche - Should defining the numFmt like you did also work for column styles? I’m doing the following but still seems to show original date format (e.g. 8/1/18) instead of expected (e.g. 01/08/2018 for format below)

worksheet.columns = [
    { header: 'Id', key: 'id', width: 10 },
    { header: 'Name', key: 'name', width: 32 },
    { header: 'D.O.B.', key: 'DOB', width: 10, style: { numFmt: 'dd/mm/yyyy' } }
];

// Via streaming
worksheet.addRow({
   id: '1',
   name: 'my name',
   DOB: new Date()
}).commit();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Format a date the way you want - Microsoft Support
Select the cells you want to format. · Press CTRL+1. · In the Format Cells box, click the Number tab. · In the...
Read more >
How to Change Date Format in Excel - Trifacta
Select the cells you want to format · Click Ctrl+1 or Command+1 · Select the “Numbers” tab · From the categories, choose “Date”...
Read more >
Excel Date and Time Formatting - My Online Training Hub
On the Number tab select 'Date' in the Categories list. This brings up a list of default date formats you can select from...
Read more >
Date format in Excel - Customize the display of your date
Usually, when you insert a date in a cell it is displayed in the format dd/mm/yyyy or mm/dd/yyyy. Let's say you have the...
Read more >
Convert Date to Text in Excel - Explained with Examples
Example 2: Converting Current Date to Text ... To convert the current date into text, you can use the TODAY function along with...
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