Change date format to dd/mm/yyyy
Change date format to dd/mm/yyyy
zer0uk
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
This discussion has been closed.
Answers
This thread should help, it's asking the same thing.
Cheers,
Colin
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(); });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
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
You have the plugin installed:
but moment js itself is missing.
See this as well please: http://live.datatables.net/jevehada/1/edit
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.
Put moment.js before datetime_moment.js.
Done but sadly still not working datatable or the ddmmyyyy formatting
Do you have errors in your browser's console?
Can you post a link to your page so we can help debug?
Kevin
link is http://mytimekeeper.co.uk/stats/stats_all.php
& thanks
You are getting this error:
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
Great that's fixed it thank you so much ...
how would I get it so its sort descending by default (from current date downwards)?
The
order
option can be used to set the initial ordering of the table. You may need to use thesorting/datetime-moment.js
you have installed to have the dates ordered correctly. This blog explains how to use it.Kevin
Thanks Kevin
"order": [0, 'dec'],
did the trick :-)