Change Date Format in Date Serialized from DataTable.rows.data()

Change Date Format in Date Serialized from DataTable.rows.data()

Eugene_BEugene_B Posts: 19Questions: 8Answers: 0

I create a string from my DataTable using

    var table = $('#advanced_search_results').DataTable();
    var displayData = table.rows({filter:'applied'}).data();
    var result = $.makeArray();
    $.each(displayData,function(index,row) {
        result.push(row);
    });

I send it to the server. When the JSON string arrives on the server, the JSON Date string contains e.g.

planCreatedDate: "Jan 21, 2020, 1:00:41 PM"

But I need it to be in a different format, yyyy-MM-dd'T'HH:mm:ss . Maybe this isn't the DataTable's problem, but is there something I can do globally for all Date fields in my object?

Answers

  • Eugene_BEugene_B Posts: 19Questions: 8Answers: 0

    I forgot one more piece, the JSON.stringify,

    var str = encodeURIComponent(JSON.stringify(result))
    
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Where is the date field coming from? If you are using Editor you can tell it what format to display, and what format to use on the wire as shown here.

    If you are using something else to get your date / time input, you'd need to refer to their documentation for how to get the date in the format you want.

    In future, as noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Allan

This discussion has been closed.