Order by date

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
george3380
Forum Newbie
Posts: 1
Joined: Wed Mar 10, 2004 9:13 am

Order by date

Post by george3380 »

Hey all php newbie here. I'm trying to order a query by a date field. I've read around and it looks like the correct sql formatting is YYYY-MM-DD, however my current date format is DD.MM.YY

I've tried the following and it is not sorting correctly (I'm guessing because of the date format):

"SELECT * FROM tbl_hq_press_releases ORDER BY pr_dateAdded DESC";

What is the easiest way to format pr_dateAdded in this statement? I've been browsing the forums and a lot of people are using a DATE_FORMAT() function, but that seems to be undocumented by php.net.

Thanks for the help.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: Order by date

Post by JayBird »

george3380 wrote:
What is the easiest way to format pr_dateAdded in this statement? I've been browsing the forums and a lot of people are using a DATE_FORMAT() function, but that seems to be undocumented by php.net.
you need to look at the MySQL manual, not the PHP one

http://www.mysql.com

Mark
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Also store your date as dates, not the text. Read mysql manual data types section.
Post Reply