Performing and age range search via use of D.O.B

Discussion in 'PHP' started by reubenrd, Feb 2, 2012.

  1. #1
    Hello

    Basically having problems trying to think of a solution for performing age range search on my database. For Example. 18years - 24years.

    I am storing the date of birth in my database as such YYYY-mm-dd

    I have tried using < >= within my mysql query but these seem to do nothing. Anyone got any idea?

    Regards
     
    reubenrd, Feb 2, 2012 IP
  2. FizixRichard

    FizixRichard Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this:

    
    select * from user where dateofbirth >= '1990-02-03 13:35:44' && dateofbirth <= '1999-02-03 13:35:44'
    
    Code (markup):
    So make the date range (start and end) for the age filter you need and compare that way. You will want to format the date/time of the start and end vars to the same format as used in the database and use the current time.
     
    FizixRichard, Feb 3, 2012 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    What data type is the date of birth column?
     
    jestep, Feb 3, 2012 IP
  4. FizixRichard

    FizixRichard Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thats a good point. My example requires a datetime field.
     
    FizixRichard, Feb 3, 2012 IP