phpSensei Posted September 4, 2007 Share Posted September 4, 2007 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... Quote Link to comment Share on other sites More sharing options...
sstangle73 Posted September 4, 2007 Share Posted September 4, 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2007 Share Posted September 5, 2007 <?php $dob = '12-jun-88'; $hours = (time() - strtotime($dob) ) / 3600; ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted September 5, 2007 Author Share Posted September 5, 2007 <?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> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 5, 2007 Share Posted September 5, 2007 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. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted September 5, 2007 Author Share Posted September 5, 2007 they enter a form if thats what you ment... yeah, I have to upgrade the script... like i said, just a challenge. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 5, 2007 Share Posted September 5, 2007 I'd use timestamp() ... ... but only for young folk. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 5, 2007 Share Posted September 5, 2007 Good point 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.