davey10101 Posted March 18, 2010 Share Posted March 18, 2010 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 More sharing options...
PFMaBiSmAd Posted March 18, 2010 Share Posted March 18, 2010 You can only sort dates when the year, month, and day fields are left-to-right, most significant field (year) to least significant field (day) Use date('Y-m-d',strtotime($correctDate)); Link to comment https://forums.phpfreaks.com/topic/195727-date-sort/#findComment-1028258 Share on other sites More sharing options...
davey10101 Posted March 18, 2010 Author Share Posted March 18, 2010 ooo didn't know that. Many thanks Link to comment https://forums.phpfreaks.com/topic/195727-date-sort/#findComment-1028263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.