Got a problem with date_format() , using this query:
SELECT name, description, pic, download, DATE_FORMAT(date_added,'%D %M %Y'), dl_num FROM database ORDER BY download DESC
Where date_added is database value. I obviously want to format date as i select it. What am i doing wrong? Looked in the manual and this looked to be the way but my syntax is wrong somewhere. Do i have to create a separate select statement for date format or something? Would it be better to format the date after the date data has been selected?
yes, its date. I think i might have to use 'as' somewhere - as Date at the end maybe? i'll try that. I've looked through a number of ebooks on sql and there is surprisingly little about the date_format() function. Am I missing a simpler way to set the date to the correct british format of day, month, year ?
There is no error given, it 'works', but the date output as expressed in date_format is ignored - the date output is still the default YYYY MM DD when results are displayed. I'm using PHP to display the results btw
Would I need to create a new date_formatted column in the table then?
No. It just means that any further reference to that formatted output within the query or, proably more importantly, within the script where you're running the query would be by that name. For instance, in a PHP script where you might be referring to that column in a result row, you would refer to it as $row['date_formatted'] instead of by the column name in the table.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
if date_added works, but date_formatted isn't, I'm thinking it's more to do with your logic. date_added should not work in the if(!reorder) part of the condition. You might want to check the logic within the page to see which sql is getting processed.