Datetime value not showing properly in jQuery data table





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I want to get the timestamp in data table . how to format my datetime in the jquery datatable function?



sql server datatime data, how to edit the columns so that i cant get the proper datetime in the data time. i have tried with type: 'date-dd-mmm-yyyy', but its not working



 2018-11-23 07:49:35.073
data type - date time


javascript



$(document).ready(function () {
$('#myTable').DataTable({
"ajax": {
"url": "/Temperature/loaddata",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "id", "autoWidth": true },
{ "data": "updatedDate", "autoWidth": true, type: 'date-dd-mmm-yyyy', targets: 0 },
{ "data": "deviceid", "autoWidth": true },
{ "data": "devicename", "autoWidth": true },
{ "data": "temp", "autoWidth": true },
{ "data": "faht", "autoWidth": true }
]
});
});


c# code



public  ActionResult loaddata()
{
using (smartpondEntities dc = new smartpondEntities())
{
var data = dc.Temperatures.OrderBy(a => a.id).ToList();
return Json(new { data = data}, JsonRequestBehavior.AllowGet);
}
}


json sample data



[{"id":1,"updatedDate":"2018-11-23T07:49:35.073","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90},{"id":2,"updatedDate":"2018-11-23T07:49:42.1","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90}]


output



/Date(1542939575073)/


exp op



23 Nov 2018 13:10:10 









share|improve this question

























  • Date is fine. It's just a matter of formatting to string. You need to format your date to expected when you displaying it.

    – Reniuz
    Nov 23 '18 at 13:22


















0















I want to get the timestamp in data table . how to format my datetime in the jquery datatable function?



sql server datatime data, how to edit the columns so that i cant get the proper datetime in the data time. i have tried with type: 'date-dd-mmm-yyyy', but its not working



 2018-11-23 07:49:35.073
data type - date time


javascript



$(document).ready(function () {
$('#myTable').DataTable({
"ajax": {
"url": "/Temperature/loaddata",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "id", "autoWidth": true },
{ "data": "updatedDate", "autoWidth": true, type: 'date-dd-mmm-yyyy', targets: 0 },
{ "data": "deviceid", "autoWidth": true },
{ "data": "devicename", "autoWidth": true },
{ "data": "temp", "autoWidth": true },
{ "data": "faht", "autoWidth": true }
]
});
});


c# code



public  ActionResult loaddata()
{
using (smartpondEntities dc = new smartpondEntities())
{
var data = dc.Temperatures.OrderBy(a => a.id).ToList();
return Json(new { data = data}, JsonRequestBehavior.AllowGet);
}
}


json sample data



[{"id":1,"updatedDate":"2018-11-23T07:49:35.073","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90},{"id":2,"updatedDate":"2018-11-23T07:49:42.1","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90}]


output



/Date(1542939575073)/


exp op



23 Nov 2018 13:10:10 









share|improve this question

























  • Date is fine. It's just a matter of formatting to string. You need to format your date to expected when you displaying it.

    – Reniuz
    Nov 23 '18 at 13:22














0












0








0








I want to get the timestamp in data table . how to format my datetime in the jquery datatable function?



sql server datatime data, how to edit the columns so that i cant get the proper datetime in the data time. i have tried with type: 'date-dd-mmm-yyyy', but its not working



 2018-11-23 07:49:35.073
data type - date time


javascript



$(document).ready(function () {
$('#myTable').DataTable({
"ajax": {
"url": "/Temperature/loaddata",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "id", "autoWidth": true },
{ "data": "updatedDate", "autoWidth": true, type: 'date-dd-mmm-yyyy', targets: 0 },
{ "data": "deviceid", "autoWidth": true },
{ "data": "devicename", "autoWidth": true },
{ "data": "temp", "autoWidth": true },
{ "data": "faht", "autoWidth": true }
]
});
});


c# code



public  ActionResult loaddata()
{
using (smartpondEntities dc = new smartpondEntities())
{
var data = dc.Temperatures.OrderBy(a => a.id).ToList();
return Json(new { data = data}, JsonRequestBehavior.AllowGet);
}
}


json sample data



[{"id":1,"updatedDate":"2018-11-23T07:49:35.073","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90},{"id":2,"updatedDate":"2018-11-23T07:49:42.1","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90}]


output



/Date(1542939575073)/


exp op



23 Nov 2018 13:10:10 









share|improve this question
















I want to get the timestamp in data table . how to format my datetime in the jquery datatable function?



sql server datatime data, how to edit the columns so that i cant get the proper datetime in the data time. i have tried with type: 'date-dd-mmm-yyyy', but its not working



 2018-11-23 07:49:35.073
data type - date time


javascript



$(document).ready(function () {
$('#myTable').DataTable({
"ajax": {
"url": "/Temperature/loaddata",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "id", "autoWidth": true },
{ "data": "updatedDate", "autoWidth": true, type: 'date-dd-mmm-yyyy', targets: 0 },
{ "data": "deviceid", "autoWidth": true },
{ "data": "devicename", "autoWidth": true },
{ "data": "temp", "autoWidth": true },
{ "data": "faht", "autoWidth": true }
]
});
});


c# code



public  ActionResult loaddata()
{
using (smartpondEntities dc = new smartpondEntities())
{
var data = dc.Temperatures.OrderBy(a => a.id).ToList();
return Json(new { data = data}, JsonRequestBehavior.AllowGet);
}
}


json sample data



[{"id":1,"updatedDate":"2018-11-23T07:49:35.073","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90},{"id":2,"updatedDate":"2018-11-23T07:49:42.1","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90}]


output



/Date(1542939575073)/


exp op



23 Nov 2018 13:10:10 






javascript c# datatables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:33









wanttobeprofessional

1,02931323




1,02931323










asked Nov 23 '18 at 13:12









krishnamohan raokrishnamohan rao

236




236













  • Date is fine. It's just a matter of formatting to string. You need to format your date to expected when you displaying it.

    – Reniuz
    Nov 23 '18 at 13:22



















  • Date is fine. It's just a matter of formatting to string. You need to format your date to expected when you displaying it.

    – Reniuz
    Nov 23 '18 at 13:22

















Date is fine. It's just a matter of formatting to string. You need to format your date to expected when you displaying it.

– Reniuz
Nov 23 '18 at 13:22





Date is fine. It's just a matter of formatting to string. You need to format your date to expected when you displaying it.

– Reniuz
Nov 23 '18 at 13:22












2 Answers
2






active

oldest

votes


















0














i use moment.js for datetimes (docs). so in your render:



{
title: "Date",// name
render: function (data, type, row) {//data
return moment(row.updatedDate).format('DD/MM/YYYY hh:mm:ss');
}
}





share|improve this answer































    0














    You should use a render function to format/customize your data



    For Ex:



    "columns": [
    { "data": "engine" },
    { "data": "browser" },
    {
    "data": "platform",
    "render": function ( data, type, row, meta ) {
    return ConvertToDate(data);
    }
    }


    Convert your date in ConvertToDate(data) function.



    function ConvertToDate(data){
    return data;//Converted date
    }





    share|improve this answer


























    • error saying - "ConvertToDate is not defined", do i need to make a another function

      – krishnamohan rao
      Nov 23 '18 at 13:51













    • you need to add a function named ConvertToDate(date)

      – Gokul Maha
      Nov 23 '18 at 13:52












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447383%2fdatetime-value-not-showing-properly-in-jquery-data-table%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    i use moment.js for datetimes (docs). so in your render:



    {
    title: "Date",// name
    render: function (data, type, row) {//data
    return moment(row.updatedDate).format('DD/MM/YYYY hh:mm:ss');
    }
    }





    share|improve this answer




























      0














      i use moment.js for datetimes (docs). so in your render:



      {
      title: "Date",// name
      render: function (data, type, row) {//data
      return moment(row.updatedDate).format('DD/MM/YYYY hh:mm:ss');
      }
      }





      share|improve this answer


























        0












        0








        0







        i use moment.js for datetimes (docs). so in your render:



        {
        title: "Date",// name
        render: function (data, type, row) {//data
        return moment(row.updatedDate).format('DD/MM/YYYY hh:mm:ss');
        }
        }





        share|improve this answer













        i use moment.js for datetimes (docs). so in your render:



        {
        title: "Date",// name
        render: function (data, type, row) {//data
        return moment(row.updatedDate).format('DD/MM/YYYY hh:mm:ss');
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 16:04









        Wilmer Ofelio Alama SeminarioWilmer Ofelio Alama Seminario

        11018




        11018

























            0














            You should use a render function to format/customize your data



            For Ex:



            "columns": [
            { "data": "engine" },
            { "data": "browser" },
            {
            "data": "platform",
            "render": function ( data, type, row, meta ) {
            return ConvertToDate(data);
            }
            }


            Convert your date in ConvertToDate(data) function.



            function ConvertToDate(data){
            return data;//Converted date
            }





            share|improve this answer


























            • error saying - "ConvertToDate is not defined", do i need to make a another function

              – krishnamohan rao
              Nov 23 '18 at 13:51













            • you need to add a function named ConvertToDate(date)

              – Gokul Maha
              Nov 23 '18 at 13:52
















            0














            You should use a render function to format/customize your data



            For Ex:



            "columns": [
            { "data": "engine" },
            { "data": "browser" },
            {
            "data": "platform",
            "render": function ( data, type, row, meta ) {
            return ConvertToDate(data);
            }
            }


            Convert your date in ConvertToDate(data) function.



            function ConvertToDate(data){
            return data;//Converted date
            }





            share|improve this answer


























            • error saying - "ConvertToDate is not defined", do i need to make a another function

              – krishnamohan rao
              Nov 23 '18 at 13:51













            • you need to add a function named ConvertToDate(date)

              – Gokul Maha
              Nov 23 '18 at 13:52














            0












            0








            0







            You should use a render function to format/customize your data



            For Ex:



            "columns": [
            { "data": "engine" },
            { "data": "browser" },
            {
            "data": "platform",
            "render": function ( data, type, row, meta ) {
            return ConvertToDate(data);
            }
            }


            Convert your date in ConvertToDate(data) function.



            function ConvertToDate(data){
            return data;//Converted date
            }





            share|improve this answer















            You should use a render function to format/customize your data



            For Ex:



            "columns": [
            { "data": "engine" },
            { "data": "browser" },
            {
            "data": "platform",
            "render": function ( data, type, row, meta ) {
            return ConvertToDate(data);
            }
            }


            Convert your date in ConvertToDate(data) function.



            function ConvertToDate(data){
            return data;//Converted date
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 14:01

























            answered Nov 23 '18 at 13:46









            Gokul MahaGokul Maha

            215519




            215519













            • error saying - "ConvertToDate is not defined", do i need to make a another function

              – krishnamohan rao
              Nov 23 '18 at 13:51













            • you need to add a function named ConvertToDate(date)

              – Gokul Maha
              Nov 23 '18 at 13:52



















            • error saying - "ConvertToDate is not defined", do i need to make a another function

              – krishnamohan rao
              Nov 23 '18 at 13:51













            • you need to add a function named ConvertToDate(date)

              – Gokul Maha
              Nov 23 '18 at 13:52

















            error saying - "ConvertToDate is not defined", do i need to make a another function

            – krishnamohan rao
            Nov 23 '18 at 13:51







            error saying - "ConvertToDate is not defined", do i need to make a another function

            – krishnamohan rao
            Nov 23 '18 at 13:51















            you need to add a function named ConvertToDate(date)

            – Gokul Maha
            Nov 23 '18 at 13:52





            you need to add a function named ConvertToDate(date)

            – Gokul Maha
            Nov 23 '18 at 13:52


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447383%2fdatetime-value-not-showing-properly-in-jquery-data-table%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]