sorting an array in date order

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Birmingham
Forum Newbie
Posts: 1
Joined: Mon Oct 08, 2007 8:16 am
Location: Birmingham, England, UK

sorting an array in date order

Post by Birmingham »

hi, can anyone give me a really simple example of sorting an array in date order please? it's strangely an issue i've been struggling with for some time now....
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Bubble

Post by N1gel »

You could try a bubble sort

Bubble
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Can you post an example array? Specifically, what format are the dates in?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you looked at any of the array sorting function in the manual?
mrkite
Forum Contributor
Posts: 104
Joined: Tue Sep 11, 2007 4:19 am

Post by mrkite »

Storing your dates in military order "YYYY-MM-DD" will let you sort dates using standard alphabetical sorting.
RobertPaul
Forum Contributor
Posts: 122
Joined: Sun Sep 18, 2005 8:54 pm
Location: OCNY

Post by RobertPaul »

If your dates aren't in YYYY-MM-DD format (which I'm pretty sure is an ISO standard rather than a military standard ;)) then you'll probably want to use usort() with a callback function that decomposes the date string, etc...
Post Reply