0
2019-11-19 15:35:52.494

This is actual data in my database table, but in the datatable I get this:

2019-11-19T10:05

The date format is wrong.

How can i solve this?

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263

3 Answers3

0

The date format is wrong.

The format is not wrong, The T is just a standard (ISO 8601) way to de-limit the time. To remove T from your datetime string you could format your string using pure Javascript something like this or you can use any other library like moment. Take a look here for formatting using moment js.

Shail_bee
  • 499
  • 4
  • 24
0

In columnDefs, add your target column

$(document).ready( function () {
  var table = $('#example').DataTable({

    columnDefs:[{targets:4, render:function(data){
      return moment(data).format('MMMM Do YYYY'); 
    }}]
  });
});

In targets put your column number and In format put the format you want to display. You can try with different format follow this below link

click here for demo

Ram Anugandula
  • 582
  • 4
  • 15
abhinavsinghvirsen
  • 1,853
  • 16
  • 25
0

If you don't necessarily need it to be a date type, you could try to cast the timestamp to text in your select statement when you retrieve it from the database, like this:

SELECT TO_CHAR(NOW(),'dd/MM/YYYY hh:mm:ss') AS date_time

Here is more info about formatting using TO_CHAR.

juan_carlos_yl
  • 641
  • 8
  • 14