Jump to content

[SOLVED] How many hours have I lived script...


Recommended Posts

listen, I am really confused about my script and I dont think this is even a little accurate...

 

Script shows how many hours, have I lived in my life...

 

how does this work?

 


<?php

$current_year = date("Y");
//This Year

$year = $_POST['year'];
//Born Year

$years_lived = $current_year - $year;
// How many years the user has lived // 
$months_total = 12 * $years_lived;
// How many months lived // 
$days_lived = 365 * $months_total;
// How many days lived //
$hours_lived = 24 * $days_lived;
// How many Hours Lived //



?>



How should I make so it takes my full birthday - today...

 

Example:

 

Born : 12, june, 1988

 

and that date minus

 

4, september, 2007...

 

heres a script that gives you age in years

 

function birthday($birthday){   
list($month,$day,$year) = explode("-", $birthday);  

$today = getdate();   
$age = $today['year']-$year;
   
if(($month > $today['mon']) || ($month==$today['mon'] && $day > $today['mday'])){   


$age--;
}

return $age;  
}

 

im not sure what your question is?  your script is only accurate on your birthday and the year is wrong if you havent had your bday this year.

 

<?php
$dob = '12-jun-88';

$hours = (time() - strtotime($dob) ) / 3600;
?>

 

I tried thhis...

 

<?php

if(isset($_POST['submit'])){

$name = trim($_POST['name']);
$yr = $_POST['year'];
$mt = $_POST['month'];
$dy = $_POST['days'];

if(($name == "")||($yr=="0")||($mt=="0")||($dy=="0")){

die("Please enter your name, and full date of birth");

}
else
{
$year_today = date ('Y');
$month_today = date ('m');
$day_today = date ('d');

$birth_day = $_POST['days'];
$birth_month = $_POST['month'];
$birth_year = $_POST['year'];


$how_many_years = $year_today - $birth_year;
$total_month = $how_many_years * 12;
$total_days = $total_month * 30;

$how_many_days_inbirth =  $total_days ; 

$total_days_1 = $how_many_days_inbirth; //5475

/////////////////////////////////////////////////////////
$count_current_month = 30 * $month_today + $day_today;  // 30 * 09 + 04

$total_days_2 = $count_current_month;
/////////////////////////////////////////////////////////

$days_lived = $total_days_1 + $total_days_2;


echo '<table width="55%" border="0" align="center" cellpadding="0" cellspacing="2">
  <tr>
    <td align="left" valign="top"><h2 align="center" class="style1">'.$name.' , we have estimated that you have lived for: <span class="style3">'.$days_lived.' days</span></h2>    </td>
  </tr>
  <tr>

Unless you allow the user to enter the time of day they were born, it won't be accurate.

You'd also have to account for where they were born, where they are, and where your server is. Time zones.

I'd use timestamp() instead of messing with the year and then multiplying it, but without the other info the closest you can be is within 24 hours I guess.

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.