My solution to date + time sorting

My solution to date + time sorting

StevenSteven Posts: 5Questions: 0Answers: 0
edited May 2010 in General
Firstly I'd like to say that this script is really excellent.

I didn't find the following solution anywhere else on the forum so I thought I'd share it.

It was important to me to display the date/time in the format 16th May 2010 1.07pm.

However there didn't seem to be an easy way to tell DataTables to sort this correctly.

What I did to solve this was immediately before the date/time is displayed in the table cell, I added the date/time again except there were two differences. The first difference was that the format of the date/time was in a very raw format which DataTables can sort numerically as opposed to sorting by date. For the above example, the output would be 20100516130734. To explain from left to right it goes 2010 (year), 05 (month), 16 (day), 13 (hour), 07 (minute) and 34 (seconds). To display like this with PHP, it is:

<?php
echo date("YmdHis", strtotime($date));
?>

The second difference is that I wrapped this date/time with CSS so as not to display it, like this:




I hope this approach helps someone. The only caveat I can think of is that it might not be very SEO friendly but I was doing it for an admin panel so it didn't matter.

Steven
This discussion has been closed.