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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:24:03+00:00 2026-05-16T02:24:03+00:00

I have birth dates on my site in format 12.01.1980 . $person_date (string) =

  • 0

I have birth dates on my site in format 12.01.1980.

$person_date (string) = Day.Month.Year

Want to add an oldness of the person. Like “Currently 30 years” (2010 – 1980 = 30 years).

But makin the function just on years can’t give the perfect result:

If person birth date is 12.12.1980 and current date is 01.01.2010 the person doesn’t have 30 years old. It’s a 29 years and one month.

There must be a calculation on targeting both year, month and day of birth with comparison of current date:

0) Parse the dates.

Birth date (Day.Month.Year):
Day = $birth_day;
Month = $birth_month;
Year = $birth_year;

Current date (Day.Month.Year):
Day = $current_day;
Month = $current_month;
Year = $current_year;

1) year comparison, 2010 – 1980 = write “30” (let it be $total_year variable)

2) compare the months, if (birth date month is bigger > than current month (like 12 in birth and 01 current)) { do minus one year from $total_year variable (30 – 1 = 29) }. If do minus happened, finish the calculations at this point. Else go the next (3 step).

3) else if (birth month < current month) { $total_year = $total_year (30); }

4) else if (birth month = current month) { $total_year = $total_year (30); }

and check the day (in this step):

 if(birth day = current day) { $total_year = $total_year; }
 else if (birth day > current day) { $total_year = $total_year -1; }
 else if (birth day < current day) { $total_year = $total_year; }

5) echo $total_year;

My php knowledge isn’t good, hope you can help.

Thanks.

  • 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-16T02:24:03+00:00Added an answer on May 16, 2026 at 2:24 am

    You can use the DateTime class and its diff() method.

    <?php
    $bday = new DateTime('12.12.1980');
    // $today = new DateTime('00:00:00'); - use this for the current date
    $today = new DateTime('2010-08-01 00:00:00'); // for testing purposes
    
    $diff = $today->diff($bday);
    
    printf('%d years, %d month, %d days', $diff->y, $diff->m, $diff->d);
    

    prints 29 years, 7 month, 20 days

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

Sidebar

Related Questions

I have the birth date from particular year, i want to find the day
I have a table users with a column date_of_birth (DATE format with day, month,
I have birth dates stored as datetime in SQL Server 2008 like so: 2010-04-25
I have a Person model, which includes a property representing the data of birth
I have an index that stores birth-dates, and I would like to search for
I have a birth_date variable in the Date format. I want to compare it
In SQL Server 2008 R2, I have to compare two dates of birth from
I have date of Birth of the format 04/08/2010(DD/MM/YYYY) and sql server store of
I have a form that allows users to enter a date of birth: ie:
I have a table, tblClient , which stored a client's date of birth in

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.