Jump to content

get rows where dob between 2 dates from mysqli


seany123

Recommended Posts

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.

 

 

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.