Date formatting JSON (remove timezone)

Date formatting JSON (remove timezone)

TheoBTheoB Posts: 4Questions: 0Answers: 0
edited May 2021 in DataTables 1.10

Hello,
I am coming to you because I have a problem when importing my data into my table.
Indeed, I receive a date in JSON but it is in this format:
Tue May 25 00:00:00 CEST 2021

I would like to retrieve it like this:
DD / MM / YYYY

I tried to fix the problem with "moment.js" but I was not successful ...

Here is my code:

$.ajax({
        'url': "https://myurl",
        type: "GET",
        dataType: "json",
        }).done( function(data) {
        
        $('#table_id').dataTable( {
            "aaData": data,
            "columns": [
                { "data": "MY_DATE"}
            ],

        })
})

Can you help me?
Thank you so much !

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You can use columns.render, see example here: http://live.datatables.net/kezeyiti/3/edit

    Colin

  • TheoBTheoB Posts: 4Questions: 0Answers: 0
    edited May 2021

    Thank you for your reply!

    I have already tried to use "columns.render", the problem is that it displays: "Invalid date"
    I have the impression that he does not understand this format ..: Thu May 27 00:00:00 CEST 2021.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • TheoBTheoB Posts: 4Questions: 0Answers: 0

    Hello, excuse me, here is the code:
    live.datatables.net/kezeyiti/170/edit
    I modified the table with my date.
    Thanks for the help!

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited May 2021

    You are using the datetime plugin. You probably need to provide the source datetime format using this syntax: $.fn.dataTable.render.moment( from, to );. You can workout the format using the moment.js format docs.

    Kevin

  • TheoBTheoB Posts: 4Questions: 0Answers: 0

    Hello Kevin,
    Thanks for these informations !
    I found out how to format my date.
    Here is the code if that helps;):
    live.datatables.net/kezeyiti/172/edit

This discussion has been closed.