Jump to content

Recommended Posts

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?

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.