Forum Moderators: open

Message Too Old, No Replies

SQL Order By

         

WebSlug

8:50 am on Jun 19, 2008 (gmt 0)

10+ Year Member



Hi,

I'm constructing a database with a number of files available.

I want the user to be able to organize the files by the dates they were uploaded.

My current select statement only orders by the day and not the month and the year.

How can I order the results of the database taking into account the day, month and year the file was uploaded?

Downloads Table

fname
FileName

created
18/04/2008

category
application


$query="SELECT * FROM Downloads WHERE category='$selcat' ORDER BY created DESC, fname";

There aren't too many entries in the database, I'm just trying to lay out the foundations. I'm happy to change the created field to another format if it makes ordering the results easier... i.e 18/04/08

For clarification, by default does SQL add a hidden date attribute for each entry inserted? Do I really need a "created" field for each file...?

WebSlug

9:42 am on Jun 19, 2008 (gmt 0)

10+ Year Member



I've changed the structure of the created field so its a date type instead of a varchar.

It seems to be working however I have to use 2008-04-12 as the format for the date. I was hoping to use 12/04/2008 or 12/04/08.

topr8

10:53 am on Jun 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you should be able to format the date you get from the recordset however you like using php or asp [whichever your application uses]

WebSlug

12:51 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



Thanks it works great now! :)

rocknbil

4:39 pm on Jun 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If this is mysql, you can format as you select.

Date and Time Functions [dev.mysql.com]