Jump to content

user 'd.o.b'


almightyegg

Recommended Posts

figured it..

$year = date("y");

$yearsold = $year - registerdyear;

$day = date("z");

$daysold = dayregisterd - $day;

if(daysold<0){

$year = date("y") - 1;

$daysold = dayregisterd - $day + 360;

}

 

hope it works, ive never tried this before

Link to comment
Share on other sites

Age: -1995 years, 18 days

hmmm...I shouldn't be born for another 1995 years  :-X

 

$year = date("y");

$yearsold = $year - $mem[year];

$day = date("z");

$daysold = $mem[day] - $day;

if($daysold<0){

$year = date("y") - 1;

$daysold = $mem[day] - $day + 360;

}

 

I put in my row:

year - 2002

day - 112

 

So the 18 is right I think...the year definitely isn't :P

Link to comment
Share on other sites

$year = date("Y");

$yearsold = $year - $mem[year];

$day = date("z");

$daysold = $mem[day] - $day;

if($daysold<0){

$year = date("Y") - 1;

$daysold = $mem[day] - $day + 365;

}

lmao i dont even know how many days there are in a year

Link to comment
Share on other sites

doesnt work  :-\

 

look try this

<?

$memyear = 2002;

$memday = 93;

$year = date("Y");

$yearsold = $year - $memyear;

$day = date("z");

$days = $memday - $day;

$daysold = 365 - $days;

if($daysold > $days){

$year = date("Y") - 1;

$yearsold = $year - $memyear;

}

echo "$daysold: $yearsold";

?>

 

today is the 95th day, its returning that ive been registerd for 367 days and 4 years, should be 5 years and 2 days...

Link to comment
Share on other sites

$year = date("Y");

$yearsold = $year - $player[year];

$day = date("z");

$days = $player[day] - $day;

$daysold = 365 - $days;

if($daysold > $day){

$year = date("Y") - 1;

$yearsold = $year - $player[year];

}elseif($daysold > 365){

$year = date("Y") + 1;

$yearsold = $year - $player[year];

}

 

This version works I believe

Link to comment
Share on other sites

Wait, if you can create a timestamp of their date of birth, you can get the number of seconds they have been born ("now" timestamp - birthdate timestamp), divide that by 86400 (the number of seconds in a day,) to get days.  Divide the days by 365 and you have how many years, then mod the days by 365 to get the remainder, and you have years and days.  Simple.

 

Basically:

 

<?php
$day = [database query to get day of birth];
$month = [database query to get month of birth IN TEXT FORMAT (ex: "august")];
$year = [database query to get year of birth];

$dob = strtotime($day . $month . $year);
$now = strtotime("now");
$sec_diff = $now - $dob;
$days = $sec_diff / 86400;
$years = floor($days / 365);
$days = $days % 365;

echo "You were born " . $years . " years, " . $days . " days ago.";
?>

 

I hope this works.  You might need to do some tweaking, but basically the $day, $month, and $year variables are what the user put into the text fields for date of birth, for day of the month, month, and year.  You also might need to do some calculations to determine whether it is a leap year, but I'm not entirely sure.

 

edit: I tested this, and it worked, the values I used for $day, $month, and $year were 17, "august" and 1989 respectively (my birthday) and it returned "You were born 17 years, 236 days ago."  The reason for the floor() function in there is becuase without it, you get a crazy long decimal for the year, floor rounds down, no matter how large the decimal is, meaning that it could be 17.99999 and it would round down to 17, which in this case is what we need, since you are also getting the hours with the mod algorithm.

Link to comment
Share on other sites

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.