sumolotokai Posted February 11, 2010 Share Posted February 11, 2010 Hello, I am having issues creating a birthday countdown script. I have tried all sorts of things as you can see. It seems that am only one step away from success but am missing something. If i have done something completely stupid, please just point me in the right direction. Sorry for the mess... $x = $_POST["name"]; if (strstr($x,"-2")) { echo "There are $x days until your birthday";} else { echo "Your date of birth is not in the correct format, please press backwards and try again.";} $y = explode("-", $x); $mydob = mktime(0,0,0,$y[1],$y[0],$y[2]); print $mydob; echo date("d/m/y", $mydob); $today = time(); settype($mydob, 'integer'); settype($today, 'integer'); echo "<br>"; print $mydob - $today; $remain = $mydob - $today; echo "<br>"; print $mydob; echo "<br>"; print $today; echo "<br>"; print date($remain); echo "<br>"; print $remain; echo "<br>"; echo "There are..." . date("m/d/y g.i:s",$remain) tml> <head> <title>Birthdate Generator</Title> </head> <body> <form action="birthday.php" method="post"> <h1>The number of days until your birthday!</h1> <p><strong>When is your next birthday dd-mm-yyyy</strong><br> <input type="text" size="25" name="name"></p> <p><input type="submit" value="send"></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
schilly Posted February 11, 2010 Share Posted February 11, 2010 well your a little off. ignore the year in their birthday unless your calculating how old they are. then you need to see if the date (day and month) is greater than the current date. if not you need to add one to the year because their birthday won't happen until next year. then create the timestamp. then take the difference from the current date. once you have the difference divide it by 86400 (number of seconds in a day. 60*60*24) and ceil it. This will give you the number of days until that date ie. birthday. hope that helps. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 11, 2010 Share Posted February 11, 2010 Here is an all-in-one page. Modify for your needs. Note: I did not include any validation of the user input. <?php $birthdate = explode('-', $_POST['name']); $day = $birthdate[0]; $month = $birthdate[1]; $year = $birthdate[2]; $today = mktime(); $birthDateThisYear = mktime(0,0,0,$month,$day); if ($birthDateThisYear<$today) { $nextBirthDate = mktime(0,0,0,$month,$day,date('Y',$today+1)); } else { $nextBirthDate = $birthDateThisYear; } $daysTillNextBirthday = floor(($nextBirthDate-$today)/60/60/24); ?> tml> <head> <title>Birthdate Generator</Title> </head> <body> <?php echo "Days till next birthday: {$daysTillNextBirthday}"; ?> <form action="birthday.php" method="post"> <h1>The number of days until your birthday!</h1> <p><strong>When is your next birthday dd-mm-yyyy</strong><br> <input type="text" size="25" name="name"></p> <p><input type="submit" value="send"></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
sumolotokai Posted February 14, 2010 Author Share Posted February 14, 2010 Thanks very much ! I used a mixture of the two solutions. 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.