Results 1 to 3 of 3

Thread: Birthday calculating script

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Birthday calculating script

    Hey everyone!

    I've written this script

    PHP Code:
    <?php
    $bday 
    $_POST['day'];
    $bmonth $_POST['month'];
    $byear $_POST['year'];

    $cday date('j');
    $cmonth date('n');
    $cyear date('Y');

    $one "1";

    if(
    $cmonth != "$bmonth"){
    if(
    $cmonth "$bmonth"){
    $age $cyear-$byear;
    echo 
    $age;

    }else{
    if(
    $cmonth "$bmonth"){
    $age $cyear-$byear-$one;
    echo 
    $age;
    }
    }
    }else{
    if(
    $cmonth == "$bmonth"){
    if(
    $cday != "$bday"){
    if(
    $cday "$bday"){
    $age $cyear-$byear;
    echo 
    $age;

    }else{
    if(
    $cday "$bday"){
    $age $cyear-$byear-$one;
    echo 
    $age;

    }
    }
    }else{
    if(
    $cday =="$bday"){
    echo 
    "Happy Birthday";
    }
    }
    }
    }
    ?>
    to calculate the age of a user and echo their age(for testing perposes).
    The problem is I think I mixed up where so of the { and } are ment to go because its echoing either -1 or 0 depening on what I input into the form(whch submits to this script)
    The birthay is in this format

    2 11 2011
    (2nd of november)

    Any help?
    Last edited by keyboard; 11-02-2011 at 09:32 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    $now date_create('now');
    $birthdate date_create('1979-04-11');
    $interval date_diff($now$birthdateTRUE);
    echo 
    'I am '.$interval->format('%y years of age');
    // outputs "I am 32 years of age" (as of the date of this post :) ) 
    http://php.net/manual/en/book.datetime.php

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

Bookmarks

Posting Permissions

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