twilitegxa Posted July 13, 2009 Share Posted July 13, 2009 Can anyone help me to write a script to determine if someone's birthday has passed or not based on form entries? The form will ask their month and date of birth, and I want a script that will determine if the birthday has passed or not. The month is called birth_month and the date is called birth_date in the form. How would I go about writing a script like this? Quote Link to comment https://forums.phpfreaks.com/topic/165754-solved-determining-if-birthday-has-passed-or-not/ Share on other sites More sharing options...
RussellReal Posted July 13, 2009 Share Posted July 13, 2009 You'd use the date function.. <?php class Now { function __construct() { $this->day = date('j'); $this->month = date('n'); } } $now = new Now(); if (($now->month <= $_POST['month']) && ($now->day < $_POST['day'])) { echo "day has passed"; } ?> also note I used a class because its cooler looking but you could just do if (date('j') < $_POST['day']) ... etc Quote Link to comment https://forums.phpfreaks.com/topic/165754-solved-determining-if-birthday-has-passed-or-not/#findComment-874344 Share on other sites More sharing options...
twilitegxa Posted July 13, 2009 Author Share Posted July 13, 2009 I'm guessing I would take the values passed from the form: '$_POST[birth_month]', '$_POST[birth_date]' and check if it is less than today's date or greater. If less than today's date, then birthday has passed. But if greater tan today's date, birthday has not passed. Another field in my form will give the person's age (named 'age'). I want to use this script to determine if what the birth year is 1994 because March has already passed. But if thy are 15 and their birth day is November 3rd, then they were born in 1995 because their birthday hasn't passed yet. If the user enters age 15, and birth date of March 23rd, then it could determine that their year of birth is Quote Link to comment https://forums.phpfreaks.com/topic/165754-solved-determining-if-birthday-has-passed-or-not/#findComment-874347 Share on other sites More sharing options...
twilitegxa Posted July 13, 2009 Author Share Posted July 13, 2009 Thanks Russell. :-) Quote Link to comment https://forums.phpfreaks.com/topic/165754-solved-determining-if-birthday-has-passed-or-not/#findComment-874355 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.