I am creating a child registration system and I need to find out how many months the children are. This is pretty easy, but I only want to extract children who are "month of birth".
What I mean by "month of birth" is if they were born on November 23, and December 23 will be their 1 month of birth. January 23rd will be their 2-month birthday. And so on...
Now my code below tells me how many months they are, but whether this is their "month of birth."
Any ideas how I can make this work?
SELECT PERIOD_DIFF( DATE_FORMAT('2011-11-23', '%Y%m'), DATE_FORMAT(birthday.meta_value, '%Y%m') ) AS months FROM $db->members AS m JOIN $db->members_meta AS birthday ON birthday.member_id = m.id AND birthday.meta_key = 'birthday' AND birthday.meta_value != '' WHERE AND m.deleted = 0 GROUP BY m.id
I think we will need to consider whether they are born in leap years (February 29), 30 and 31 months. I found this code that works for thei search
( 2012 % 4 <> 0 OR ( 2012 % 100 = 0 AND 2012 % 400 <> 0 ) ) AND '11-23' = '03-01'
source share