locked
Date Time format with Jquery Datatables RRS feed

  • Question

  • User349356202 posted

    Greetings,

    My Jquery Datatable displays date time format (27/03/2018 18:35:50) like this /Date(1224043200000)/.
    How can i fix that and display it like it is in the database?

    I have tried this function and it works but it's lacking 0's in the date format therefore it cannot be sorted or filtered in the datatable.

    { "data":"CreationDate",
    "render": function (data) {
    var dateString = data.substr(6);
    var currentTime = new Date(parseInt(dateString));
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    var date = day + "/" + month + "/" + year;

    return date;
    }

    Thank you.

    Thursday, April 12, 2018 2:51 PM

Answers

  • User36583972 posted

    Hi MedNasser,

    How can i fix that and display it like it is in the database?

    I have tried this function and it works but it's lacking 0's in the date format therefore it cannot be sorted or filtered in the datatable.

    You can JQuery.render function and convert the datetime to the specified template.

    JQuery.render render HTML views based on the specified templates and data. It can automatically process all kinds of data, including collections, JSON objects.

    $(function() {
        var table = $('#myTable').DataTable({
            data: datas.rows,
            "columns": [{
                    title: "Time",
                    data: "Datetime",
                    render: function(d) {
                       return moment(d).format("DD:MM:YYYY HH:mm:ss");
                    }
                }, {
                    title: "Temperature",
                    data: "Temperature"
                }
            ]
        });
    })


    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 13, 2018 7:06 AM