PDA

View Full Version : How would I...



L?KE
26-10-2008, 06:59 PM
display items from a SQL database in order of date and time from those closest to the current date to those furthest away?

For example:

29-10-2008 18.00
28-10-2008 18.00
29-10-2008 17.00

Would come out as:

28-10-2008 18.00
29-10-2008 17.00
29-10-2008 18.00

Thnks, +rep xx

Decode
26-10-2008, 07:05 PM
set the field type to date + time in PhpMyAdmin, then do

SELECT * FROM `tablename` ORDER BY `tablename`.`colname`

L?KE
26-10-2008, 07:08 PM
I did wonder if that was possible, cheers. Does that work with self-inserted dates?

Invent
27-10-2008, 01:51 PM
Why not just insert a unix timestamp and then convert it into your custom date format later.

Iszak
27-10-2008, 02:35 PM
Simon is right, the unix timestamp will ensure precision (to the second) and will not require you to convert via a series of regex or explodes etc. All you'll have to use the date function for displaying it date("d/m/Y", $timestamp);

Want to hide these adverts? Register an account for free!