seany123 Posted April 24, 2015 Share Posted April 24, 2015 can anyone see why this is not working? or how to make it work? im trying to get all the rows where dob is between dob is a date field <?php $todayDate = date("Y-m-d"); $minage = date("Y-m-d", strtotime($todayDate . "-18 years")); $maxage = date("Y-m-d", strtotime($todayDate . "-99 years")); $query = mysqli_query($db, "select * from users where `dob` BETWEEN '$minage' AND '$maxage'"); ?> if i replace $minage and $maxage and type in a date manually then it works. any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/295811-get-rows-where-dob-between-2-dates-from-mysqli/ Share on other sites More sharing options...
Solution Barand Posted April 24, 2015 Solution Share Posted April 24, 2015 You need to specify the earlier date of the range first (BETWEEN earlier AND later) You can do it entirely in the SQL WHERE dob BETWEEN CURDATE() - INTERVAL 99 YEAR AND CURDATE() - INTERVAL 18 YEAR Quote Link to comment https://forums.phpfreaks.com/topic/295811-get-rows-where-dob-between-2-dates-from-mysqli/#findComment-1509801 Share on other sites More sharing options...
seany123 Posted April 24, 2015 Author Share Posted April 24, 2015 thanks yeah i worked it out with loads of tinkering. Quote Link to comment https://forums.phpfreaks.com/topic/295811-get-rows-where-dob-between-2-dates-from-mysqli/#findComment-1509807 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.