Jump to content

Need help with a date function


kevinkhan

Recommended Posts

I am scraping Birthdays from a webpage that are in this format

September 15, 1987

 

$age = 15;

$page = source code of a html page;

 

so far i have made this function

 

How do i return the function as true if the date scaped makes the person over 15 and false if the person is younger?

 

function checkForAge($page,$age) {
  preg_match('|Born on ([a-zA-Z]*\s[0-9]*,\s[0-9]*)\\\u003c\\\/span>|', $page, $match);
    if($match && count($match)>0) {
        echo "Match Found";
	$dateOfBirth = str_replace(",","",$match[1]);
//	$dateOfBirth = date('d/m/Y', strtotime($dateOfBirth));
$dateOfBirth = strtotime($dateOfBirth);
	/*

       if("date of birth makes person over $age)
         {
          return true;
         }
       else 
        {
         return false;
         }
*/

    }

Link to comment
Share on other sites

If you get your date of birth into a YYYY-MM-DD format, the following will calculate a person's age in whole years -

 

$today = date("Y-m-d");
$age = substr($today, 0, 4) - substr($dob, 0, 4) - (substr($today, 5,5) < substr($dob, 5,5)); // difference in years, subtract one if the birthday has not occurred yet in the current year

Link to comment
Share on other sites

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.