Project 1999

Go Back   Project 1999 > General Community > Off Topic

Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2024, 09:27 AM
willey4983 willey4983 is offline
Decaying Skeleton


Join Date: Jul 2024
Posts: 1
Default How to Calculate Age in Years, Months, and Days?

I'm working on a project that requires calculating the exact age of individuals in years, months, and days. I've tried a few different methods but I'm not confident that I'm doing it correctly.

Can anyone provide a reliable formula or method to accurately calculate someone's age from their birthdate to the current date? Any code examples or step-by-step explanations would be greatly appreciated! Thank you!
Reply With Quote
  #2  
Old 07-15-2024, 04:35 PM
Tann Tann is offline
Planar Protector

Tann's Avatar

Join Date: Oct 2010
Posts: 1,061
Default

Excel, put a date in A1 then use:

Code:
=DATEDIF(A1, TODAY(), "Y") & " years, " & DATEDIF(A1, TODAY(), "YM") & " months, and " & DATEDIF(A1, TODAY(), "MD") & " days"
__________________
< Knights Who Say Ni >
Qeynos questing and leveling (all quests nerfed) | Off the beaten path 24-40.
Reply With Quote
  #3  
Old 07-15-2024, 05:05 PM
Duik Duik is offline
Planar Protector

Duik's Avatar

Join Date: Oct 2017
Location: Near the largest canyon in the world!
Posts: 1,664
Default

Homework question?
1st post from user.
Seems to be an odd request on an elf sim forum.

Here is a hint for anyone. If you have tried a few different methods mention and list them showing where you think you went wrong.

People do not know how to ask questions. No wonder the interwebs is full of nitwits.
Reply With Quote
  #4  
Old 07-15-2024, 05:10 PM
Smoofers Smoofers is offline
Kobold

Smoofers's Avatar

Join Date: Jun 2021
Location: Cheap Bastardville
Posts: 155
Default

If only there was a tool that could tell you exactly how to do this
Reply With Quote
  #5  
Old 07-15-2024, 06:57 PM
magnetaress magnetaress is offline
Planar Protector

magnetaress's Avatar

Join Date: Feb 2020
Location: Inside of you.
Posts: 9,647
Default

Do you have api access or library access to time and date functions? Most languages already handle this.

If you're making your own functions that requires an underlying understanding of time and dates that I cannot provide.

I'm 9999% sure Javascript handles things like this in its basic library and you just got to learn what functions to call and feed it the relevant data.
__________________
Apophis is closest to earth on 2029 April the 13th (a friday) lol
Reply With Quote
  #6  
Old 07-15-2024, 07:28 PM
magnetaress magnetaress is offline
Planar Protector

magnetaress's Avatar

Join Date: Feb 2020
Location: Inside of you.
Posts: 9,647
Default

https://www.javatpoint.com/cpp-date-and-time

https://www.google.com/search?q=time...hrome&ie=UTF-8

obviously JS, perl, sh, and python all have their own... dunno if 'ruby' is its own thing i been outa the biz a long time
__________________
Apophis is closest to earth on 2029 April the 13th (a friday) lol
Reply With Quote
  #7  
Old 07-15-2024, 07:29 PM
magnetaress magnetaress is offline
Planar Protector

magnetaress's Avatar

Join Date: Feb 2020
Location: Inside of you.
Posts: 9,647
Default

you'll probably have to convert time to something more tangible, do ur maths, then convert ur strings back

like convert it all to seconds, add, do ur maths, then feed ur seconds back into one of the time strings

so like take current date and old date and convert both to seconds, do maths, then convert seconds back to days/hrs/months etc back to something more human readable

ONE of those functions may or may not do that for u, or part of it, u got to dig around in the documentations
__________________
Apophis is closest to earth on 2029 April the 13th (a friday) lol
Last edited by magnetaress; 07-15-2024 at 07:32 PM..
Reply With Quote
  #8  
Old 07-17-2024, 03:50 PM
a3n5ql2 a3n5ql2 is offline
Decaying Skeleton


Join Date: Jul 2024
Location: Portland, Oregon
Posts: 4
Default

First, extract the birthdate and current date components (year, month, day). Then, calculate the difference in years, months, and days. Adjust the calculation if the day of the birth month is greater than the current day.

Here's a Python code example:

Code:
from datetime import date

def calculate_age(birthdate):
    today = date.today()
    
    years = today.year - birthdate.year
    months = today.month - birthdate.month
    days = today.day - birthdate.day
    
    # Adjust if current day is less than birthdate day
    if days < 0:
        months -= 1
        # Calculate days in previous month
        last_month = today.month - 1 if today.month > 1 else 12
        last_month_year = today.year if today.month > 1 else today.year - 1
        days_in_last_month = (date(last_month_year, last_month + 1, 1) - date(last_month_year, last_month, 1)).days
        days += days_in_last_month
    
    # Adjust if current month is less than birthdate month
    if months < 0:
        years -= 1
        months += 12
    
    return years, months, days

# Example usage
birthdate = date(1990, 5, 15)  # Replace with the actual birthdate
age = calculate_age(birthdate)
print(f"Age: {age[0]} years, {age[1]} months, {age[2]} days")
In this code, we first import the date class from the datetime module to handle date objects. Then, we define the calculate_age function, which takes a birthdate as input. We get today's date using date.today() and calculate the difference in years, months, and days between today’s date and the birthdate. Adjustments are made if the current day is less than the birthdate day by subtracting one month and adding the correct number of days from the previous month. Similarly, if the current month is less than the birthdate month, we subtract one year and add the correct number of months.

I hope this is what you're looking for, or at least something similar.
Reply With Quote
  #9  
Old 08-03-2024, 06:35 AM
Rimitto Rimitto is offline
Sarnak

Rimitto's Avatar

Join Date: Dec 2018
Posts: 295
Default

math
Reply With Quote
  #10  
Old 08-03-2024, 09:16 AM
Duik Duik is offline
Planar Protector

Duik's Avatar

Join Date: Oct 2017
Location: Near the largest canyon in the world!
Posts: 1,664
Default

^ Bot
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:49 AM.


Everquest is a registered trademark of Daybreak Game Company LLC.
Project 1999 is not associated or affiliated in any way with Daybreak Game Company LLC.
Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.