Jump to content

[SOLVED] telling age


chanfuterboy

Recommended Posts

hi, in register user put a date a month and a year. so i want that in profile it show the age exact. e.g 14-12-2007 so in profile it need to come age 2

 

i have written a code here but it show online the whole date

 

<?php echo floor(gregoriantojd(date('m'),date('d'),date('y'))-gregoriantojd(date('m',strtotime($row['DateOfBirth'])),date('d',strtotime($row['DateOfBirth'])),date('y',strtotime($row['DateOfBirth'])))/365);?>

 

can someone help my out

Link to comment
https://forums.phpfreaks.com/topic/174461-solved-telling-age/
Share on other sites

I am not sure if you tried to calculate the age of a user based on the birth date they entered, but if so and you want to do it in php's side you could do it also with DateTime class (required php >= 5.3 though).

 

<?php
// Create a new DateTime object with the user entered date.
$birthDate = new DateTime('1983-03-21 12:00:00');

// Calculate difference to today.
$diff = $birthDate->diff(new DateTime());

// Echo age.
echo $diff->y . ' years, ' . $diff->m . ' months, ' . $diff->d . ' days'; 

Link to comment
https://forums.phpfreaks.com/topic/174461-solved-telling-age/#findComment-919550
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.