redarrow Posted November 18, 2008 Share Posted November 18, 2008 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)." "; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted November 18, 2008 Author Share Posted November 18, 2008 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> Quote Link to comment Share on other sites More sharing options...
corbin Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted November 18, 2008 Author Share Posted November 18, 2008 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> Quote Link to comment Share on other sites More sharing options...
zq29 Posted November 19, 2008 Share Posted November 19, 2008 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"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.