Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    Need help with a date function

    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?

    PHP Code:
    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;
             }
    */

        

    Last edited by kevinkhan; 01-31-2011 at 05:42 PM.

  • #2
    New Coder
    Join Date
    Dec 2010
    Location
    IA
    Posts
    41
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    /* get the birth year */
    $birth_year strftime("%Y"strtotime($dateOfBirth));
    /* get the current year */
    $current_year strftime("%Y"strtotime("now"));

    /* subtract birth_year from current_year to get age difference */
    $calc_age $current_year $birth_year;

    if(
    $calc_age $age){
    return 
    true;
    }
    else{
    return 
    false;

    also, remove $dateOfBirth = strtotime($dateOfBirth);

    On second thought, this won't take into account the day of birth, only year. This may or may not be good enough.
    Last edited by ecco; 01-31-2011 at 06:18 PM. Reason: this is pretty crude and probably won't work

  • Users who have thanked ecco for this post:

    kevinkhan (01-31-2011)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ecco View Post
    PHP Code:
    /* get the birth year */
    $birth_year strftime("%Y"strtotime($dateOfBirth));
    /* get the current year */
    $current_year strftime("%Y"strtotime("now"));

    /* subtract birth_year from current_year to get age difference */
    $calc_age $current_year $birth_year;

    if(
    $calc_age $age){
    return 
    true;
    }
    else{
    return 
    false;

    also, remove $dateOfBirth = strtotime($dateOfBirth);

    On second thought, this won't take into account the day of birth, only year. This may or may not be good enough.

    Thanks that worked


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •