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 9 of 9
  1. #1
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts

    Dates before 1970

    Ok.

    I have been trying to do this all day, to no avail.

    I am trying to take a YYYY-MM-DD date from a database and calculate the age of the person. It works fine until I try to do someone who was born before 1970.

    Is it even possible to calculate someones age if they were born before 1970?

    If so, how?

    Appreciate your time
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).
    I'm pleased that they found a work around for this. The downside is that its only available on versions 5.1.0+.
    In otherwords, you cannot work with date functions if your version is older than this, and cannot support negative numbers. I believe this will lead you to your only alternative: manual calculations (or to move to a unix platform )
    PHP Code:
    <?php

    $birthday 
    '1955-06-13';
    list(
    $BYear$BMonth$BDay) = explode('-'$birthday);

    $CYear date('Y');
    $CMonth date('m');
    $CDay date('d');

    $age 0;

    if (!empty(
    $BYear) && $BYear $CYear)
    {
        
    $age += $CYear $BYear;
    }

    if (!empty(
    $BMonth) && !empty($BDay))
    {
        
    $monthDiff $CMonth $BMonth;
        
    $dayDiff $CDay $BDay;

        if (
    $monthDiff || ($monthDiff == && $dayDiff 0))
        {
            
    $age -= 1;
        }
    }
    ?>
    That should work for ya. Though I have a feeling this is easier to do... where's marek and raaf when you need them, lol.
    Last edited by Fou-Lu; 01-05-2007 at 02:59 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Thanks guys for the input... I'll check it out ASAP

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    NP mate.
    The link posted for you *should* work on a windows platform as well. Its negative, but not out of bounds on a 32 bit signed integer. I'd recommend trying it using that method as opposed to mine if you can - mine currently doesn't account for any dls areas.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    The code from the link above doesn't seem to work on windows, as I get this error whenever I try to find the age of someone born before 1970:

    Warning: mktime() [function.mktime]: Windows does not support negative values for this function in **PHP FILE** on line 49
    So, I'm trying Fou-Lu's code now...

    Quote Originally Posted by Fou-Lu
    mine currently doesn't account for any dls areas.
    What does that mean? DayLight Savings?

    If so, how does that affect this script?

    Pardon my ignorance and thanks for all your help

    Dan

    EDIT: Plugged Fou-Lu's code in, works like a charm!! (I'm still interested in finding out what you mean about 'doesn't account for any dls areas', though)

    Thanks so much!
    Last edited by whizard; 01-05-2007 at 04:25 AM. Reason: Update
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    NP, you guessed it correct.
    By dls I refer to both the daylight savings and what I never thought of earlier, timezone offsets. The only difference it would create is being +/- 24 hours from the given time, meaning you may be off as much as one day. But it will be valid from the timezone stated in, which is probably GMT. Won't create an overly high difference, unless you are planning on using the concept in a calender that is accessed by different users, only then would you be interested in making alterations if you allow the users to state their timezone offsets and daylight savings times. Which is actually, easy to do.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    OK- Thanks for all your time!

    I'm just putting my friends/contacts into a local DB and the script alerts me if its their b-day.. Therefore, I don't think DLS/timezones should be an issue.

    Thanks Again
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts

    No problem mate.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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