Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Calculate age in PHP based on DOB?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 369
    Comment on it

    Hello Reader's,
    Sometimes we require to calculate the age of user from the date of birth to current date during registration of a new user to check whether he/she is eligible or not to participate in any competitions. In that case, you need to calculate the user age from date of birth.

    This quick tutorial will guide you about how to calculate age in PHP based on date of birth

    and the current date. Here is short code snippet given below.

     

    <?php
    
        $DOB = "13-03-1990";
        $today = date("Y-m-d");
        $difference = date_diff(date_create($DOB), date_create($today));
        echo 'Your age is '.$difference->format('%y');
    
    ?>

    In the above code date(), date_create(), and date_diff() functions are used to calculate age of the user.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: