Jump to content

get rows where dob between 2 dates from mysqli


Go to solution Solved by Barand,

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.

 

 

 

 

  • Solution

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.