Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:06:39+00:00 2026-06-07T11:06:39+00:00

I have users in a MySQL database, where their birthdays are stored in a

  • 0

I have users in a MySQL database, where their birthdays are stored in a DATE format (yyyy-mm-dd). I want to select users in the database with PHP who are between a certain age range.

What I have is a minimum age(18) and a maximum age(21). I know I can do something with BETWEEN, but the problem is that I only know the years and not the dates.

Does anyone have a suggestion on how I can do this?

This is what I’m doing currently:

function leeftijden($age) { 
    $morgen['day']   = date('d'); 
    $morgen['month'] = date('m'); 
    $morgen['year']  = date('Y') - $age;

    $datum = $morgen['year'] .'-' .$morgen['month'].'-' .$morgen['day'];

    return $datum;
}

Then I do this:

$maxDatum = leeftijden(18);
$minDatum = leeftijden(32);
$sqlRijder = "SELECT * FROM rijder WHERE geboortedatum between '".$minDatum."' AND '".$maxDatum."'";

But this doesn’t work 100%.

How can I only select users who are between 18 and 21 years of age?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:06:43+00:00Added an answer on June 7, 2026 at 11:06 am

    You can simply do it right in the query:

    SELECT * 
    FROM rijder 
    WHERE geboortedatum BETWEEN 
        CURDATE() - INTERVAL 21 YEAR AND 
        CURDATE() - INTERVAL 18 YEAR
    

    This way, you do not need a special PHP function to construct a DATE string. Simply pass in the numbers and MySQL will make the comparisons for you. Just make sure the higher number comes first in the BETWEEN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Essentially I have a mysql database with users and their corresponding date of birth.
So I have a mySQL database with a 'users' table which includes a username,
I'm using a MySQL database. I have a products database where users can search
I have a sample page that uses 2 PHP files and a MySql database,
i have created a forum using php/mysql and users login through facebook using php
I have a membership program written with PHP and using mysql where users input
I have a mysql database of users that can login to my site and
Scenario: I have users that want to be able to change their username (unfortunately
I have a MySQL database full of user information, like their username, password, email,
So I have a MySQL database that I'm using with a PHP site. Over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.