Re: Sorting Dates in this format: Jul 21 2001
| From: | Ron Wills | Date: | Thu, 09 Aug 2001 16:55:38 +0000 |
| Subject: | Re: Sorting Dates in this format: Jul 21 2001 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62013@lists.php.net to get a copy of this message | ||
Hey Chris
If the text field only contains dates, I'd suggest converting it to a DATE type the use
DATE_FORMAT in your SELECT statement to return the format needed. This also lets MySQL sort it for
you,
ie:
SELECT DATE_FORMAT(date, '%b %e %Y') FROM your_table ORDER DESC BY date
Right off hand I don't think there's a simple way to sort it in PHP. If you want to
keep it as a text field then you'll probable have to parce the dates and sort it accordingly,
ie:
foreach ($dates as $date)
$parced_dates[] = split(' ', $date);
// Your own sort functions
sort_by_years($parced_dates);
sort_by_months($parced_dates);
sort_by_days($parced_dates);
I hope this helps
Chris wrote:
> I have a bunch of dates like this:
> Jul 24 2001
> Jul 31 2001
> Aug 7 2001
>
> I need to sort it from oldest to newest, but I can't devise a way that works. And they are
> text fields in MySQL so that won't sort it correctly either. Can anyone point me in the right
> direction?
--
Ron Wills
DMS Control Programmer
ron@dmscontrol.com