Change date format to dd/mm/yyyy

Change date format to dd/mm/yyyy

zer0ukzer0uk Posts: 13Questions: 2Answers: 0

Hi all the data in my mySQL database and app is using yyyy/mm/dd is there a way I can get datatable to display as dd/mm/yyyy please ?

This question has an accepted answers - jump to answer

Answers

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

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    Thanks Colin .. had a look at the thread and pinched the code but it still isn't updating to dd/mm/yyyy

    $(document).ready( function () { $('.sidenav').sidenav(); $(".dropdown-trigger").dropdown(); $('#rides').DataTable({ "scrollX": true, "autoWidth": false, columnDefs: [ { targets: [0], render: $.fn.dataTable.render.moment( 'DD/MM/YYYY' ) } ], }); $(".dropdown-trigger").dropdown(); });
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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.

    Cheers,

    Colin

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0
    edited April 2020

    Thanks Colin you should be able to get to the live site and see the problem via

    http://mytimekeeper.co.uk/stats/stats_all.php

  • rf1234rf1234 Posts: 2,982Questions: 87Answers: 421

    You have the plugin installed:

    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.20/sorting/datetime-moment.js"></script>
    

    but moment js itself is missing.

    <!-- Moment.js: -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
    

    See this as well please: http://live.datatables.net/jevehada/1/edit

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    Thanks I have added the js but still it is not working also dataTable is not running the table it is just html I think there is something wrong in the code I've added.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Put moment.js before datetime_moment.js.

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    Done but sadly still not working datatable or the ddmmyyyy formatting

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945

    Do you have errors in your browser's console?

    Can you post a link to your page so we can help debug?

    Kevin

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0
  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    & thanks

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945

    You are getting this error:

    Uncaught TypeError: $.fn.dataTable.render.moment is not a function

    For the datetime moment renderer you need to install the plugin as described here:
    https://datatables.net/plug-ins/dataRender/datetime

    Its different than the https://cdn.datatables.net/plug-ins/1.10.20/sorting/datetime-moment.js plugin you have installed.

    Kevin

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    Great that's fixed it thank you so much ...

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    how would I get it so its sort descending by default (from current date downwards)?

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945
    Answer ✓

    The order option can be used to set the initial ordering of the table. You may need to use the sorting/datetime-moment.js you have installed to have the dates ordered correctly. This blog explains how to use it.

    Kevin

  • zer0ukzer0uk Posts: 13Questions: 2Answers: 0

    Thanks Kevin

    "order": [0, 'dec'],

    did the trick :-)

This discussion has been closed.