Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-21-2011, 06:20 PM Calculate Age?
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
It's definitely not as easy as it sounds.

Say you were given somebody's birthday. The year, the month, and the day. For our example we will use 1970/05/05 (May 5th, 1980).

Now we take today's date, 2011/02/21 (Feb 21st, 2011).

What I've done is removed the slashes, and then subtracted today's date from the user's birthday, with a decimal after the year. Example:

2011.0221 - 1970.0505

The result given is not correct, however. This is because of leap years, and months having a different number of days.

How could I calculate an age when given a birthday?

I have also tried converting the string to base12, and then subtracting, but it's still off.

I've thought about it, and come up with a solution. Does PHP have any sort of time function (I know of strtotime), one that could calculate this sort of thing?

Thanks!!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-21-2011, 06:52 PM Re: Calculate Age?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Have you tried using strtotime() which will convert a string into an unix timestamp integer?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 02-21-2011, 06:58 PM Re: Calculate Age?
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
I have, but I don't know if you can simply just subtract the two values it would give you, could you?
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
Old 02-21-2011, 07:13 PM Re: Calculate Age?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.php.net/manual/en/functio...iff.php#102245
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-21-2011, 09:55 PM Re: Calculate Age?
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Thanks, chrishirst!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to Calculate Age?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21042 seconds with 12 queries