how do I export date as csv in a different format

how do I export date as csv in a different format

jimbizjimbiz Posts: 14Questions: 5Answers: 1

I'm using an Export CSV button in my table.

I need the date displayed in the table like this: Aug 3, 3:10pm.

But I wanted it exported in this format: 2020-08-03 15:10:00.

As well, the date is in the first column and I need it sorted ascending.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    There are quite a lot of posts on this in the forum. It is a lot of work and you need to understand the intricacies of MS Office for many use cases.

    This is a fairly comprehensive thread. But you'll find more:
    https://datatables.net/forums/discussion/comment/167672/#Comment_167672

  • jimbizjimbiz Posts: 14Questions: 5Answers: 1
    Answer ✓

    I only need CSV, not Excel, so I'm not sure if that's the case.

    However, here is how I did solve the issue.

    I set up two aliases for the date field (start):

    Field::inst('games.start', 'start_display')
      ->getFormatter(Format::datetime(
        'Y-m-d H:i:s',
        'j M H:i'
      ))
      ->set(false),
    Field::inst('games.start', 'start_timestamp')
      ->set(false),
    

    Then I changed the first column to sort by timestamp and added the second timestamp column and set visibility to false (also added timestamp column th to table):

    {
        data: {
          _: "start_display",
          sort: "start_timestamp"
        }
    },
    {
        data: "start_timestamp",
        "visible": false
    },
    

    Then I added the "columns: ':not(:first-child)'" to exportOptions so the displayed first column date won't be exported and the timestamp second column will be:

    {
      extend: 'csv',
      text: 'Export CSV',
      exportOptions: {
        orthogonal: 'export',
        columns: ':not(:first-child)'
      }
    },
    
This discussion has been closed.