Download free stock photos on Dreamstime. Free registration

Reply LinkBack Thread Tools Search this Thread
Old 12-09-2008, 02:08   #1 (permalink)
laksh_khamesra
Registered User
 
Join Date: Sep 2008
Posts: 13
How to take out user's AGE in PHP?

This code i have made to take out age of the user(the date in the mktime is just for testing). But many problems are occurring like if the user was born on 2nd of a month today is 1st of a month then the date comes in minus (-) which makes it too confusing... After all, i m completely stuck & confused. Please tell how to take out users age.

PHP Code:
$td mktime(0,0,0,05,24,1991);
$td1 time();

$aa date("Y"$td);
$bb date("Y"$td1);
$age $bb $aa;

$cc date("m"$td);
$dd date("m"$td1);
$month $dd $cc;

$ee date("d"$td);
$ff date("d"$td1);
$days $ff $ee;

echo 
"$age years, $month months and $days days"
  Reply With Quote
Old 12-09-2008, 07:45   #2 (permalink)
Cborrow
I like code.
 
Join Date: Dec 2004
Location: Chesapeake, VA
Posts: 297
Send a message via AIM to Cborrow
__________________

Last edited by Cborrow : 12-09-2008 at 14:27.
  Reply With Quote
Old 12-09-2008, 07:57   #3 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 6,875
Did not work when I tried it, sorry.
__________________
  Reply With Quote
Old 12-09-2008, 07:58   #4 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 6,875
11 months out.
__________________
  Reply With Quote
Old 12-09-2008, 08:21   #5 (permalink)
Cborrow
I like code.
 
Join Date: Dec 2004
Location: Chesapeake, VA
Posts: 297
Send a message via AIM to Cborrow
Yeah, I'm not sure what it is but mktime returns the month as 12. If I change the day to 09 the month changes to 11. Anthing over Aug 9th renders the month as 12.

Edit: Find a function online that seems to do what you want.

time since [date] [php] [time] [since]
__________________

Last edited by Cborrow : 12-09-2008 at 14:24.
  Reply With Quote
Old 12-09-2008, 17:19   #6 (permalink)
feha
Design Destroyer
 
feha's Avatar
 
Join Date: Aug 2008
Location: Somewhere in Universe
Posts: 198
__________________
SIGNATURE ?
  Reply With Quote
Old 15-09-2008, 09:03   #7 (permalink)
combatsheep
trained to kill
 
combatsheep's Avatar
 
Join Date: Apr 2008
Location: Liverpool, UK
Posts: 133
Send a message via MSN to combatsheep
PHP Code:
<?php
$date 
strtotime("11/04/1984"); // could be your sql result or timestamp

$day date('jS',$date);
$month date('F',$date);
$year date('Y',$date);


echo 
"My birthdate is the $day of $month , $year";
?>

Remember date() accepts US dates by default so 4/11/1984 in US is 11/04/1984.

look at php.net/date for formatting options.
  Reply With Quote
Old 15-09-2008, 09:12   #8 (permalink)
feha
Design Destroyer
 
feha's Avatar
 
Join Date: Aug 2008
Location: Somewhere in Universe
Posts: 198
@combatsheep
I think he wanted to calculate the age on given date ...
not date conversion
__________________
SIGNATURE ?
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive
Web Hosting by Heart Internet, vBulletin © 2000-2009 Jelsoft Enterprises Limited.
Search Engine Optimization by vBSEO 3.0.0 RC8
Web Hosting by Heart Internet