MyBB Community Forums

Full Version: sort users by birthday?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to display a variation of the memberlist that is meant to sort the users by their birthday.

I have tried
$years = array(
  "1970" => "1970",
  "1971" => "1971",
  "1972" => "1972",
  "1973" => "1973",
  "1974" => "1974",

  foreach($years as $year => $year_name) {

$query = $db->query("SELECT * FROM mybb_users u LEFT JOIN mybb_userfields f on (u.uid=f.ufid) WHERE f.fid20 LIKE '%$year%' AND u.uid NOT IN (1560) ORDER BY  CAST(u.birthday AS signed) ASC");

But the output is rather random. 
birthday in mybb_users is entered as  6-7-2018, so I tried sorting the list using
ORDER BY SUBSTRING_INDEX('u.birthday','-',-1) ASC");

I don't care about the months as much as I care about the years, but whatever variety of this method I've tried, the output is always the same - the list gets sorted by uid instead. 

Can anyone help me how to get the list sorted by the user's birthday (just the year will do).