Jump to content

date sort


davey10101

Recommended Posts

Hi, I have a series of dates in the following format to display in a graph.  I've managed to convert the dates to dd-mm-yyyy but want to sort the array by date..

The date is originally pulled from an email in the format "30 November 2009" then placed into a db in separate columns 'day', 'month', 'year'  so the my array would originally look like this:

 

$datetosort[] = "30 November 2009";
$datetosort[] = "24 November 2009";
$datetosort[] = "23 November 2009";
$datetosort[] = "20 November 2009";
$datetosort[] = "9 December 2009";
$datetosort[] = "5 December 2009";
$datetosort[] = "3 December 2009";
$datetosort[] = "1 December 2009";

foreach($datetosort as $correctDate){
$value[] = date('d-m-Y',strtotime($correctDate)); 
}

print_r($value);

 

changed format is like this in array:

 

Array ( [0] => 30-11-2009 [1] => 24-11-2009 [2] => 23-11-2009 [3] => 20-11-2009 [4] => 09-12-2009 [5] => 05-12-2009 [6] => 03-12-2009 [7] => 01-12-2009 )

 

now I want to sort into date order, any ideas?  Cheers  :-*

Link to comment
https://forums.phpfreaks.com/topic/195727-date-sort/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.