Page 1 of 1

Posted: Sat Apr 10, 2004 3:40 am
by malcolmboston
one of the times i used the DATE FORMAT function i was then unable to sort by the date?

is this a normal side effect or was there something wrong in my script?

Posted: Sat Apr 10, 2004 4:39 am
by timvw
probably this query does not what you want it to do

select date_format(date, '....') as date order by date

this one does

select date_format(date,'....') as nicedate order by date

Posted: Sat Apr 10, 2004 4:42 am
by malcolmboston
why the.....

...... nicedate?

whats the difference?

Posted: Sat Apr 10, 2004 5:41 am
by timvw
the first query would sort on the formatted output


say you have some timestamps, you want to date_format so that it shows the day...

select date_format(timestamp,'%a') as timestamp from stuff order by timestamp

now the sorting would be on monday, tuesday, ...

thus saturday comes before wednesday

Posted: Sat Apr 10, 2004 5:23 pm
by Steveo31
The nicedate is there as... I guess like a variable where the DATE_FORMAT is stored. That way, someone could do

Code: Select all

DATE_FORMAT( `input_date` , '%c-%e-%y' ) AS rev_date
and then get it back by a

Code: Select all

while($row = mysql_fetch_array($theQuery)){
echo $row['rev_date'];
}