How do I show timestamp column as date?

How do I show timestamp column as date?

adammorlandadammorland Posts: 2Questions: 0Answers: 0
edited April 2009 in General
I have a table and one of the columns shows the timestamp from my MySQL database.

I would like the this column to sortable by timestamp, but display as dd/mm/yyyy or something similar.

Any help would be greatly appreciated!

/Adam

Replies

  • allanallan Posts: 57,737Questions: 1Answers: 9,204 Site admin
    Hi Adam,

    It's perhaps worth having a look through the forum as this has already been addressed a couple of times. Have a look at this thread: http://datatables.net/forums/comments.php?DiscussionID=81 (among others)

    You can add plug-in sorting functions as described on the plug-ins page: http://datatables.net/plug-ins
    And this is an example of a custom sort and type detection in action: http://datatables.net/examples/example_sorting_plugin.html

    Hope this helps,
    Allan
  • adammorlandadammorland Posts: 2Questions: 0Answers: 0
    Thanks Allan,

    I spent a long time reading those before posting this discussion as I couldn't get it to work. Currently I have it displaying the timestamp unformatted so that the sort works, I just need to display the date though without the time. The installation is 'straight off the shelf', I have changed nothing from the default download.

    When I use PHP to change the timestamp to display as a date then the sorting goes out as it sorts it in numerical order of the date. eg:

    24/11/2009
    23/12/2009 <---
    23/11/2009
    22/11/2009

    I'm not very up on javascript so your help (and patience) would be greatly appreciated!
  • allanallan Posts: 57,737Questions: 1Answers: 9,204 Site admin
    Hi Adam,

    It's probably worth having a look at this discussion as well then http://datatables.net/forums/comments.php?DiscussionID=122#Item_8 - it gives the exact sorting functions and how to implement it for UK date sorting. Hopefully that will do the trick for you :-)

    Allan
This discussion has been closed.