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 3218452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:31:46+00:00 2026-05-17T15:31:46+00:00

After some research and little afford from myself I got this: $query .= SELECT

  • 0

After some research and little afford from myself I got this:

     $query .= "SELECT * FROM users WHERE birthday < SUBDATE(NOW(), INTERVAL BETWEEN $min AND $max YEAR)";

Although this doesn’t work.

Users birthdays are stored in: 1991-01-01 in the birthday column. I have two fields in my form, that you can enter numbers in. example, 18 and 22.

then it will show all users that has the age between 18 and 22 ( 18,19,20,21,22).

^ And that is what im trying to filter out, with the query. But ive done something wrong, and maybe you cant do BETWEEN in INTERVAL, or what is wrong?

Im getting:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BETWEEN 17 AND 21 YEAR)' at line 1
  • 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-05-17T15:31:46+00:00Added an answer on May 17, 2026 at 3:31 pm

    But ive done something wrong, and maybe you cant do BETWEEN in INTERVAL, or what is wrong?

    Exactly – BETWEEN is a boolean operator, which means it returns a boolean value (true or false), and INTERVAL wants an integer.

    WHERE birthday
      BETWEEN SUBDATE(NOW(), INTERVAL $max YEAR)
          AND SUBDATE(NOW(), INTERVAL $min YEAR)
    

    and a warning – you better have those variables properly escaped (with mysql_escape_string). Bobby Tables!

    Also note that: using NOW() means that you would be including people born 17 years 23 hours ago, but excluding people born 18 years and 1 hour ago. That is not typically what we mean by “birthday” – you would better use TODAY() than NOW().

    However, with TODAY(), there is another issue: BETWEEN is inclusive; thus, between 18 and 20, you do not have 2 years, but 2 years and a day. Overcome this by splitting BETWEEN up and doing normal comparison (birthday > ... AND birthday <= ...)

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

Sidebar

Related Questions

[Edited: After cross-testing on a fresh machine and some additional research, this appears to
After some stupid musings about Klingon languages, that came from this post I began
I have a specific task and after doing some research, I feel a little
I'm looking to remove the all parentheses from a given string. After some research,
Need to get rid of jsessionid from my url. After some research on the
I ask sorry if this argument has already been covered, but after some research
I am currently writing a paper on the Android platform. After some research ,
After doing some research on the subject, I've been experimenting a lot with patterns
After some find and replace refactoring I ended up with this gem: const class
after I did some research on the subject, I found that Windows Live stopped

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.