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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:51:28+00:00 2026-06-04T21:51:28+00:00

Is there any PHP function to convert current age to date in YYYY-MM-DD format.

  • 0

Is there any PHP function to convert current age to date in YYYY-MM-DD format. I stored the DOB in YYYY-MM-DD format and I want to run the SQLite query:

SELECT FirstName FROM mytable WHERE DOB >= $MinAge AND DOB <= '$MaxAge';

I searched google to convert age to date format but could not find any function, is there anyone who can help?

  • 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-04T21:51:29+00:00Added an answer on June 4, 2026 at 9:51 pm

    Is there any PHP function to convert current age to date

    No, an age contains less information than a date. There are 365 possibilities for a person to be X years old, but a date of birth maps to exactly one age.

    In other words, if I tell you that I’m 20, and ask you to tell me my birthday, you can’t with certainty. If I tell you my birthday, however, you can then, with certainty, tell me my age.

    As your column is called DOB, I’ve assumed that you’ve stored the date of birth, not the age. In this situation, it is possible to fetch users falling a certain age range.


    Let’s assume that you want to find all users between the ages of 18 and 50 (including 18 and 50).

    For a user to be 18 today, his birthday must be:

    • before or on today - 18 years
    • after today - 19 years

    For a user to be 50 today, his birthday must be:

    • before or on today - 50 years
    • after today - 51 years

    Note that “before or on” and “after” are just “<=” and “>”, respectively.

    So, what if you want all users who are between 18 and 50 years old?

    You can just take the two outer bounds:

    A user’s age is between 18 and 50 iff:
    dob <= (today -18 years) and dob > (today - 51 years)

    $lower = date('Y-m-d', strtotime('today -18 years'));
    $upper = date('Y-m-d', strtotime('today -51 years'));
    $query = "SELECT FirstName FROM users WHERE dob >= '$lower' AND dob < '$upper';";
    

    Note that if you plan on dates before 1970 (52-ish), you should likely use DateTime instead of date and sttrtotime (I actually only use DateTime in actual code, but date/strtotime make for much briefer examples).

    An example of 85 years ago with DateTime:

    $d = new DateTime('today -85 years');
    $s = $d->format('Y-m-d'); //1927-06-03 as of 3 June 2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there is any php function to convert the number of
Is there any PHP library or function to convert MP3 files to lower quality?
Is there any function like php's mb_convert_encoding which can convert an encoding to another?
Possible Duplicate: PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL] Hope everyone
Is there any function in PHP to make the first character of the word
Is there any reasons why PHP's json_encode function does not escape all JSON control
Is there any way that I could enjoy a decodeValue() function in PHP, too?
Is there any function available in PHP to check whether an array is empty
Is there any equivalent function that returns the character at position X in PHP?
Is there any way to differentiate IE7 versus IE6 using PHP's get_browser() function?

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.