Date Format

Date Format

ridgeandgableridgeandgable Posts: 3Questions: 2Answers: 0

I have my datatable working but I'm trying to change the date to the dd/mm/yyyy format.

If I use this

moment.updateLocale(moment.locale(), { invalidDate: "Invalid Date Example" });

                    var table = $('#test').DataTable({
                        columnDefs: [{
                            targets: 3,
                                        render: $.fn.dataTable.render.moment('DD/MM/YYYY' ),
                        }],
                    });
                    } );

it works perfectly, but when I put everything together, it doesnt

<script>
            $(document).ready( function () {
          $('#test').DataTable({
          paging: false,
          searching: true,
        scrollY: 600,
                    "order": [[ 6, "asc" ]],
                    moment.updateLocale(moment.locale(), { invalidDate: "Invalid Date Example" });

                    var table = $('#test').DataTable({
                        columnDefs: [{
                            targets: 3,
                                        render: $.fn.dataTable.render.moment('DD/MM/YYYY' ),
                        }],
                    });
                    } );

      </script>

Also, I have multiple date fields on this table (3 & 6), how do I make it work with more than 1?

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    edited April 2022

    It is unclear what you trying to achieve.
    And I don't know what this is supposed to do:

    moment.updateLocale(moment.locale(), { invalidDate: "Invalid Date Example" });
    

    Let's assume this is only about rendering ...

    $(document).ready( function () {
        moment.updateLocale(moment.locale(), { invalidDate: "Invalid Date Example" });
        var table = $('#test').DataTable({
            paging: false,
            searching: true,
            scrollY: 600,
            order: [[ 6, "asc" ]],
            columnDefs: [{
                targets: [3, 6], 
                render: $.fn.dataTable.render.moment('DD/MM/YYYY' )
            }],
        });
    } );
    
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    edited April 2022

    It looks like line 8 should be moved to between 2 and 3 like @rf1234 suggests. @ridgeandgable you should be getting a Javascript syntax error in the browser when trying to run that code.

    Allan

Sign In or Register to comment.