Results 1 to 6 of 6

hw to calculate the age in PHP?

This is a discussion on hw to calculate the age in PHP? within the Web Design forums, part of the Web Designing & Development category; Hi friends. can anybody tell me the code for calculate the perfect age in PHP. I m looking for a ...

  1. #1
    Moderator Array orlando's Avatar
    Join Date
    Sep 2008
    Posts
    111

    Default hw to calculate the age in PHP?

    Hi friends.
    can anybody tell me the code for calculate the perfect age in PHP. I m looking for a code that can show the perfect age date, time , month.

    thanks

  2. #2
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Re: hw to calculate the age in PHP?

    Does you mean calender?

  3. #3
    Moderator Array orlando's Avatar
    Join Date
    Sep 2008
    Posts
    111

    Default Re: hw to calculate the age in PHP?

    No buddy.
    My mean is if anybody register on my site, my site show the exact date of birth of user with his profile.
    hope you understand

    thanks

  4. #4
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Re: hw to calculate the age in PHP?

    Ok my dear
    here is a php script for displaying actual date of birth of user.

    Code:
    <div class="fields">
    [COLOR=#000000][COLOR=#0000BB]<?php
        $year_diff [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Y"[/COLOR][COLOR=#007700]) - ([/COLOR][COLOR=#0000BB]$user[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]profile_dob[/COLOR][COLOR=#007700]{[/COLOR][COLOR=#0000BB]year[/COLOR][COLOR=#007700]});
        [/COLOR][COLOR=#0000BB]$month_diff [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"m"[/COLOR][COLOR=#007700]) - ([/COLOR][COLOR=#0000BB]$user[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]profile_dob[/COLOR][COLOR=#007700]{[/COLOR][COLOR=#0000BB]month[/COLOR][COLOR=#007700]});
        [/COLOR][COLOR=#0000BB]$day_diff [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"d"[/COLOR][COLOR=#007700]) - ([/COLOR][COLOR=#0000BB]$user[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]profile_dob[/COLOR][COLOR=#007700]{[/COLOR][COLOR=#0000BB]day[/COLOR][COLOR=#007700]});
        if ([/COLOR][COLOR=#0000BB]$month_diff [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700])
          [/COLOR][COLOR=#0000BB]$year_diff[/COLOR][COLOR=#007700]--;
        elseif ([/COLOR][COLOR=#0000BB]$month_diff [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000BB]0 [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]$day_diff [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700])
          [/COLOR][COLOR=#0000BB]$year_diff[/COLOR][COLOR=#007700]--;
    [/COLOR][COLOR=#0000BB]?>[/COLOR][/COLOR]
    <p>AGE: [COLOR=#000000][COLOR=#0000BB]<?php [/COLOR][COLOR=#007700]print [/COLOR][COLOR=#0000BB]$year_diff[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]?>[/COLOR][/COLOR] </p>
    </div>

  5. #5
    Moderator Array orlando's Avatar
    Join Date
    Sep 2008
    Posts
    111

    Default Re: hw to calculate the age in PHP?

    Thanks for the reply.
    But i found it.
    $age = floor((time() - strtotime($birthdate))/(60*60*24*365.2425));
    i m not implement this. but i think it works.

    thanks

  6. #6
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Re: hw to calculate the age in PHP?

    That code is not sufficient. may be it will work....i am not sure but you have another code also what i suggest you before.



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
  •  
SEO Forum | Web Hosting Forum | Websites For Sale |