troubleshooting Question

Sort Date YYYY MM DD help!

Avatar of waffe
waffeFlag for United States of America asked on
PHP
11 Comments3 Solutions595 ViewsLast Modified:
Hi,

I have been trying to use ksort() and usort()  to arrange a list of dates in order from current to last. 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  ksort, but when the dates print they are not sorted. I know it has something to do with how I'm creating the date array but I'm lost.

Thanks,
waffe
$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($videosMostPopularMediaData); $i++){
		$fullDate = $videosMostPopularMediaData[$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";
	}
	ksort($ISOSDates);
	print_r($ISOSDates);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros