Page 1 of 1
[SOLVED]Sorting on date?
Posted: Tue Oct 19, 2004 9:10 am
by Diod
I dont know if this is the right categorie to ask,
but how do i sort on date (oldest as last and newest as first)
when $date is for my date and $row["time"] is for my time ?
Posted: Tue Oct 19, 2004 9:20 am
by nigma
Append this to your mysql query:
This man page might help you out:
http://dev.mysql.com/doc/mysql/en/Sorting_rows.html
Posted: Tue Oct 19, 2004 9:29 am
by Diod
thx
and if i want to order by date AND by time?
Posted: Tue Oct 19, 2004 9:33 am
by feyd
read the last example in his link.
Posted: Tue Oct 19, 2004 9:34 am
by Diod
if i understand it correctly, i just do
Code: Select all
$result = mysql_query("SELECT * FROM news order by date, time desc",$db);
EDIT: it works, even without order by time..
it seems to order by date AND time even if i only use date
Posted: Thu Oct 21, 2004 7:51 am
by dreamline
At first i also used 2 fields, however if you have multiple time and dates in your database like i did double the fields.. For instance i had 3 fields for time and 3 fields for date so basically 6 fields, i changed that to 3 fields.
And did an order by date,'dd-mm-yyyy hh:mm:ss' desc (european notation)..
Looked around at the mysql help and you can filter out all the values for day, month, year with something like %m or so.. Have a look at the manual for the exact stripping...
Hope this helps a bit..

Posted: Thu Oct 21, 2004 6:18 pm
by feyd
I believe dreamline is referring to [mysql_man]extract[/mysql_man]