Jump to content

date diffrence problam (how long have you been a live date(h:i:s)


redarrow

Recommended Posts

advance thank you....

 

 

How can i show the proper in hours minutes and secounds off a person's life

 

example...

 

currently im getting the dob from a form in the

format off day 1-31 and month 1-12 and year 1940-2008

 

what do i do to get the day minutes and hours there alive

<?php

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

$d=$_POST['d'];
$m=$_POST['m'];
$y=$_POST['y'];

$submitted_date=$d.$m.$y;

$form_timestamp= mktime(0, 0, 0, date($d), date($m), date($y));

$date_now=time();

$years_old=($date_now - $form_timestamp);

echo "YOU ARE IN GMT TIME, THIS MUCH OLD ".date("h:i:s",$years_old)." ";
?>

Here the full code in one page should work.........

 

Should show the current users life in hours dosent......

 

<?php

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

$d=$_POST['d'];
$m=$_POST['m'];
$y=$_POST['y'];

$submitted_date=$d.$m.$y;

$form_timestamp= strtotime($submitted_date);

$date_now=time();

$years_old=(($date_now )- ($form_timestamp));

echo "YOU ARE IN GMT TIME, THIS MUCH OLD ".date("h",$years_old)." ";


}

?>

<table align="center" border="0">
<tr>
<td valign="middle" align="center">

PLEASE ENTER YOUR DATE OF BIRTH!

<br>

<br>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<table align="center" border="0">

<tr>

<td valign="middle" align="center">

DAY <br>
<select name='d'>

<?php for($i=1; $i<32; $i++){ ?>
<option value="<?php echo $i;?>"><?php echo $i ?></option>
<?php }?>

</select>

</td>

<td valign="middle" align="center">
MONTH <br>
<select name='m'>

<?php for($i=1; $i<13; $i++){ ?>
<option value="<?php echo $i;?>"><?php echo $i ?></option>
<?php }?>

</select>

</td>


<td valign="middle" valign="center">
YEAR <br>
<select name='y'>

<?php 
$y=range(1930,2008);
for($i=0; $i<count($y); $i++){ ?>
<option value="<?php echo $y[$i]; ?>">
<?php echo $y[$i]; ?></option>
<?php }?>

</select>

</td>

</tr>

</table>

<br>

<input type="submit" name="submit" value="SEND!">

</form>

</td></tr>

</table>

I don't feel like writing it out, but it's basically a crap load of logic:

 

 

$years = $uyears - $cyear - 1;

 

Then if the current month and day are past the user's b-day, ++$years.

 

 

Simple stuff like that.  Just logic it out.

this should work then.......

 

result

 

1262306008

 

 

<?php

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

$d=$_POST['d'];
$m=$_POST['m'];
$y=$_POST['y'];


$submitted_date= $d.$m.$y;
   

   	function calculateAge($submitted_date)
   
      {
   
      $dob = explode(' ', $submitted_date);
   
      $dobYear = $dob[0];
   
      $dobMonth = $dob[1];
   
      $dobDay = $dob[2];
   
       
   
      
   
      $age = date('Y') - $dobYear;
  
       
  
      if(date('n') < $dobMonth & date('j') < $dobDay)
  
      {
  
              $age–;
  
      }
  
       
  
      return $age;
  
      }

echo calculateAge($submitted_date);
}

?>

<table align="center" border="0">
<tr>
<td valign="middle" align="center">

PLEASE ENTER YOUR DATE OF BIRTH!

<br>

<br>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<table align="center" border="0">

<tr>

<td valign="middle" align="center">

DAY <br>
<select name='d'>

<?php for($i=1; $i<32; $i++){ ?>
<option value="<?php echo $i;?>"><?php echo $i ?></option>
<?php }?>

</select>

</td>

<td valign="middle" align="center">
MONTH <br>
<select name='m'>

<?php for($i=1; $i<13; $i++){ ?>
<option value="<?php echo $i;?>"><?php echo $i ?></option>
<?php }?>

</select>

</td>


<td valign="middle" valign="center">
YEAR <br>
<select name='y'>

<?php 
$y=range(1930,2008);
for($i=0; $i<count($y); $i++){ ?>
<option value="<?php echo $y[$i]; ?>">
<?php echo $y[$i]; ?></option>
<?php }?>

</select>

</td>

</tr>

</table>

<br>

<input type="submit" name="submit" value="SEND!">

</form>

</td></tr>

</table>

Wouldn't it just be something like this?

<?php
$now = time();
$dob = strtotime("1985-12-16");

$diff = $now - $dob;

$m = $diff / 60;
$s = $diff % 60;
$h = round($m / 60);
$m = $m % 60;

echo "Approx. $h Hours, $m Minutes, $s Seconds";
?>

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.