Date time format

Date time format

enghosamenghosam Posts: 2Questions: 0Answers: 0
edited February 2014 in General
hey all, i faced a problem with date time field format in editable data table , it always comes '/Date(1390687200000)/ '

please, kindly can any one help me?

thanks in advance

Replies

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    You will have to provide more information.
    http://www.datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
  • enghosamenghosam Posts: 2Questions: 0Answers: 0
    ok tangerine ...

    my sql database table column is with datetime datatype ..
    my datatable column with type date :

    {
    "label": "Created On",
    "name": "CreatedOn",
    "type": "date",
    "dateFormat": "yy-mm-dd"
    }
    when retrieving data from my server, the data table column must shows the proper datetime format .. but it never occurred it always shows a strange data value looks like this : /Date(1390687200000)/
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    Please provide a test case as explained in the link:
    http://www.datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    > Date(1390687200000)

    Looks like an epoch timestamp in milliseconds to me (seconds since 1st Jan 1970) - but it might be something else.

    You will need to format the date into something readable using DATE_FORMAT or whatever SQL function is appropriate for your database. Editor's PHP libraries have date formatting options built in, how you do it using other scripts will depend entirely on how those scripts work.

    Allan
  • EkosterEkoster Posts: 12Questions: 0Answers: 0
    Hi, just wanted to post my solution. I get this too, for from my source I select datetime from a mssql database. If you look with fiddler (a great tool for seeing what happens) you see the JSON has this format you get. If you look in the code in visual studio express and capture what you got before passing it to JSON you see something like "{12/12/2012 12:12}". So actually the cause is the JSON.

    My solution was to put this piece of code in the specific column in the datatable definition
    [code]"mRender": function (data, type, full) {
    var dtStart = new Date(parseInt(data.substr(6)));
    var dtStartWrapper = moment(dtStart);
    return dtStartWrapper.format('DD/MM/YYYY HH:mm');
    }
    [/code]

    Please note my site already uses moment.js
This discussion has been closed.