peterjc Posted February 7, 2009 Share Posted February 7, 2009 I would like to know how to get the people birthday between two date. Example: i want to select all people birthday from February 3 to March 15. Could someone show me or give me idea how to write the SQL query to select between the day and month? Thank. Quote Link to comment https://forums.phpfreaks.com/topic/144190-mysql-select-birthday-between-two-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 7, 2009 Share Posted February 7, 2009 Either use the mysql MONTH() and DAY() functions or the DATE_FORMAT() function to get just the month and day from your date of birth column and then use a BETWEEN comparison to test for the min and max values you want. Quote Link to comment https://forums.phpfreaks.com/topic/144190-mysql-select-birthday-between-two-date/#findComment-756680 Share on other sites More sharing options...
peterjc Posted February 7, 2009 Author Share Posted February 7, 2009 really sorry guy. I know a bit how to use month() day() and DATE_FORMAT() actually, but i really can not figure out how to write the sql statement for this case! Could you please write an example? Example: SELECT mem_dob FROM `membership` WHERE mem_dob BETWEEN ....... I really does not know how to continue at the end Thank in advance. Quote Link to comment https://forums.phpfreaks.com/topic/144190-mysql-select-birthday-between-two-date/#findComment-756783 Share on other sites More sharing options...
peterjc Posted February 8, 2009 Author Share Posted February 8, 2009 After try for several hours, if finallly come out with this: SELECT * FROM `membership` WHERE date_format( mem_dob, '%m-%d' ) BETWEEN date_format( '2009-02-03', '%m-%d' ) AND date_format( '2009-03-15', '%m-%d' ) Could someone please tell me will this code work correctly? I have try it seem to be correct but may be there are some case that i do not considered. Quote Link to comment https://forums.phpfreaks.com/topic/144190-mysql-select-birthday-between-two-date/#findComment-757224 Share on other sites More sharing options...
fenway Posted February 8, 2009 Share Posted February 8, 2009 There are tons of examples if you search this forum or read the commments on the relevant mysql refman page. Quote Link to comment https://forums.phpfreaks.com/topic/144190-mysql-select-birthday-between-two-date/#findComment-757377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.