vj5 Posted April 9, 2008 Share Posted April 9, 2008 I have a date field which is in varchar character. I want to do sorting as below:Right now, it displays:12/2007 12/2006 11/2007 11/2006 10/2007 10/2006 I want sort this order to:12/200611/200610/200612/2007 and so on.I am trying to work this out but is not working as expected:here is my code:$B = array(); foreach ($docs as $asofstart){ list($m,$y) = split($docs,"/"); array_push($B,"$y:$m"); }This is my first part. I am trying to echo $B, it gives me ARRAY as result. Please tell what is wrong and how I should do it. Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2008 Share Posted April 9, 2008 1. to "echo" an array, use print_r($array);2. to do custom sorting, use usort($array, $function);The callback function will be passed two array values at a time, so it's job is to evaluate them. That's where you'd do your splitting and so on. Read about it here: http://us2.php.net/usort Link to comment Share on other sites More sharing options...
vj5 Posted April 9, 2008 Author Share Posted April 9, 2008 1. to "echo" an array, use print_r($array);2. to do custom sorting, use usort($array, $function);The callback function will be passed two array values at a time, so it's job is to evaluate them. That's where you'd do your splitting and so on. Read about it here: http://us2.php.net/usort Thanks, I have another problem. When I enter the date, I can enter in such a way : 04/2007, only this works. But I want to try entering 4/2007,4/2007,04/07,042007 in different formats, how will i do it. can someone please help. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 9, 2008 Share Posted April 9, 2008 I don't even know what you're asking with that last question, you can store anything you want in a varchar field. If you want to try entering different values, then dust off your keyboard and do it. But if you're storing a date, use a date field. Then it will at least sort correctly. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.