Sort Array of Dates in YYYY MM DD help!
Posted: Wed Dec 16, 2009 1:48 am
Hi,
I have been trying to use ksort() usort(), mktime() and just good old sort() to sort an array of dates and they are all slapping me in the face saying NO!
Currently, I have parsed a list of dates from a database into YYYY MM DD format and added them all to an array to be sorted with sort but this does not work.
I have been trying to use ksort() usort(), mktime() and just good old sort() to sort an array of dates and they are all slapping me in the face saying NO!
Currently, I have parsed a list of dates from a database into YYYY MM DD format and added them all to an array to be sorted with sort but this does not work.
Code: Select all
$ISOSDates = array();
//Select the date in the media(api)data and split it into an array
//Format the date into ISO (YYYY-MM-DD) and use ksort to put it in order
for($i = 0; $i < sizeof($mediaData); $i++){
$fullDate = $mediaData[$i]['uploaded_date'];
//splits the $fulldate array into its components
list($dayName, $month, $dayNum, $time, $timetype, $year) = split('[ ]', $fullDate);
//populate the the array with dates to be sorted
$ISOSDates[$i] = "$year-$month-$dayNum";
}
$sortedDates = sort($ISOSDates, SORT_STRING);