Jump to content

Recommended Posts

Sorry, went off to do a bit of research. I'm not 100% sure on this, but I don't think it matters...

Seconds in a normal year: 3600 * 24 * 365 = 31,536,000
Seconds in a leap year: 3600 * 24 * 366 = 31,622,400
Seconds used in my function: 31,556,926 (Reported by Google - "seconds in a year")

Maybe googles answer is some kind of average that accounts for the difference caused by leap years? I really don't know to be honest.

Also, I've realised that my function won't work on all systems - negative timestamps are only supported in PHP5 and on *NIX based operating systems...

//my example playing with the timestamp.

<?

function redarrow($birthday){

$d=date("d")+8;
$m=date("m")+4;
$y=date("y")+67;

$my_birth_date=date("$d$m$y");

$my_age=$y-42;

$birthday=date("y")-31;
$today_date=date("y-m-d");

if($birthday < $today_date ) {

echo " Your birthday was on the $my_birth_date I am  $my_age years old ";

}
}
redarrow($birthday);

?>
mine:
[code]
<?php
//all values must be without leading 0. Not sure why,lol
$current_year = date("Y");
$current_month = date("n");
$current_day = date("j");
$dob_day = 21;
$dob_month = 9;
$dob_year = 1989;
$age = $current_year-$dob_year;
if($dob_month >= $current_month){
  $age--;
}

if($dob_month == $current_month && $dob_day >= $current_day){
  $age++;
}

echo $age;
?>
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.