datatime value display

datatime value display

agg9505agg9505 Posts: 11Questions: 5Answers: 0
edited April 2017 in Free community support

Hy im trying to show a value datetime '2017-01-01 12:00:00.000' and the datatable show this '/Date(1483297200000)/'
how can I set the column type/format?

//////code//////

columns: [
                    {
                        "data": "Id", "visible": true,
                        render: function (data, type, row) {
                            //alert(type);
                            if (type === 'display') {

                                return row.Id + '  <input  type="hidden" id="Id" name="Id" value="' + row.Id + '">'
                            }

                            //  return data;

                        }
                    },
                    { "data": "User", "visible": true },
                    { "data": "Date", "visible": true }, //probelm here
                    { "data": "Type1", "visible": true },
                    { "data": "ContactName", "visible": true },
                     { "data": "LastUpdate", "visible": true },//here too
                      { "data": "AssigTo", "visible": true },
                       { "data": "AssigDate", "visible": true },
                        { "data": "Priority", "visible": true },
                         { "data": "Status", "visible": true },
                          { "data": "Done", "visible": true }

                ]

This question has an accepted answers - jump to answer

Answers

  • bsukbsuk Posts: 92Questions: 26Answers: 2
    Answer ✓

    Try using moment.js in columndefs section:

    {
    "targets": 2,
    "render": function(data){
     return moment(data).format("DD/MM/YYYY HH:mm:ss");
     }
    },
    
  • agg9505agg9505 Posts: 11Questions: 5Answers: 0

    @bsuk Thank you!

  • agg9505agg9505 Posts: 11Questions: 5Answers: 0

    also can be solved like this i you dont wanna use de momnet.js

     "data": "Date", "visible": true,
                               render: function (data, type, row) {
                                   if (row.Date !=null) {
                                       var date = new Date(parseInt(row.Date.substr(6)));
                                       return (date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear())
                                   }
                                   return data;
                                   
                                  
                               }
    
    
This discussion has been closed.