Edit Date Format

Edit Date Format

TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

So I am attemting to edit a date that is displayed yyyy/mm/dd hh:mm:ss into dd/mm/yyyy.
I believe I installed moment.js and added to my scrip before datatables. Then for render I have this.
I don't get any error, but the date stays in the same format. I have looked through a few examples and tried them, but none seem to work.

{ "data": "OrderDtl_NeedByDate",render : $.fn.dataTable.moment('DD/MM/YYYY')},











<script type='text/javascript'>

    var resData = <%-(data)%>;

    $(document).ready(function(){
        $('#OpenOrders').DataTable( {
  dom: 'Blfrtip',
            lengthMenu:  [[10, 25, 50, -1], [10, 25, 50, "All"]],
            buttons: [{extend: 'excel' , className: 'badge badge-info'},
            {extend: 'pdf' , className: 'badge badge-info'},
               ],

            "data": resData.value,

            "columns": [
            { "data": "OrderHed_OrderNum", },
    { "data": "OrderDtl_OrderLine" },
    { "data": "OrderHed_PONum" },
    { "data": "OrderDtl_XPartNum" },
    { "data": "OrderDtl_length_c",},
    { "data": "OrderDtl_Pieces_c", },
    { "data": "OrderDtl_OrderQty",render: $.fn.dataTable.render.number( ',', '.', 2, '' )},
    { "data": "Calculated_ShipPCS",render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
    { "data": "Calculated_AvailablePCS",render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
    { "data": "Calculated_ReadyPCS",render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
    { "data": "OrderDtl_DocUnitPrice" },
    { "data": "OrderDtl_NeedByDate",render : $.fn.dataTable.moment('DD/MM/YYYY')},

        ]

        });


    })

</script>

This question has an accepted answers - jump to answer

Answers

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0
    edited July 2020

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    When you say edit, are you using Editor or some other approach? I'm not seeing Editor in your code samples?

    Colin

  • kthorngrenkthorngren Posts: 21,448Questions: 26Answers: 4,974
    Answer ✓

    { "data": "OrderDtl_NeedByDate",render : $.fn.dataTable.moment('DD/MM/YYYY')},

    In line 27 you are trying to use this to format the date. $.fn.dataTable.moment('DD/MM/YYYY')} is used to define the datetime format used for sorting when using the plugin described in this blog. You will want to use the moment.js library for this. Something like this:

    { "data": "OrderDtl_NeedByDate",
      render: function(data) {
                  return moment(data).format('DD/MM/YYYY');
      }
    },
    

    Here is another recent thread discussing a similar question.

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    This did it.

    { "data": "OrderDtl_NeedByDate",},

            ],
    
            columnDefs: [{
                      targets: 11,
                      render: function(data) {
                      return moment(data).format('YYYY/MM/DD'); }
                      }],
    
This discussion has been closed.