I have ArrayDataProvider with field of type DateTime - birthdate. I use that dataprovider for a gridview in view section.
Since birthdates include the birthyear the sorting is not working as expected. Is there a way to somehow tell the sorting mechanism not to account years and only sort by month and day ? A custom sort function perhaps ?
Edit: Something like sort in C++ where you can pass the compare function.
Edited current solution description: My solution currently is to include a birthyear as a separate field in array and birthdate's years are set to current year. Now dates are from the same year and the sorting works. But separate field for birth year doesn't feel right. I wish i could get all necessary data from one date object.
This separate field grinds my gears. It's not perfect.
Edit: Oh, and its Yii2
Update There are also a PHP array sorting functions that take a compare callback - for example uasort that can be used on associative arrays like mine:
uasort($persons, function($a, $b){
return strcasecmp( $b['date']->format('m-d'), $a['date']->format('m-d') );
});
Now i need to find the way to implement it into ArrayDataProvider. Any ideas here ?