Date formatting JSON (remove timezone)
Date formatting JSON (remove timezone)
TheoB
Posts: 4Questions: 0Answers: 0
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 !
This discussion has been closed.
Replies
You can use
columns.render
, see example here: http://live.datatables.net/kezeyiti/3/editColin
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.
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
Hello, excuse me, here is the code:
live.datatables.net/kezeyiti/170/edit
I modified the table with my date.
Thanks for the help!
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
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