SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with Year < 1900

    Hi

    I have a situation, where we input ages. The application is for older people. therefore, it might happen that some one is older and his date of birthe is 1899 or 1892 etc. He will definately a lucky guy having this much long age. But what i ahve come to know that PHP has a limitation of backward timpstamp. That is t cant go beyond 1900.

    I am using mktime() function, so is there any way out to this ?

    Regards

  2. #2
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Why do you need to use a timestamp for age input? You could just use a field type of "int" or "tinyint". How is this field going to be used?

    D

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't use a timestamp for something like that. A date is more complex. Since you probably use a database for storing the dates anyway, you can also use the database's date handling functions. That is -- Store dates in the database as type DATETIME, and do all date-based algebra in the database.

  4. #4
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually the situatino is to calculate the EXACT date. That include a policy that if the next date of birthe is within 240 days then Age = Age + 1 other wise age = age. Moreover, there are 4 ages and we have to check which one is the YOUNGER and which one is the older. And we need to calculate the Exact age. Not 2007 - Year of birther. Like my Birthday is 20/05/1979, then 2007-1979 = 28 but actually i m not 28 years now. there are still 20 days to go. Another example is like suppose your birthe day is 31-12-1980 then 2007 - 1980 = 27 but u are not 27 at this point. There are still 8 months. so your age is 26 these sort of calculation i have to made and then i have to check the younger and older also.

    Please guide.

  5. #5
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I get ya ... I suppose I would go with kyberfabrikken's advice

  6. #6
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can u people gudie me how to do my tasks through that u 've suggested ?

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To calculate the difference in years, between two dates:
    Code:
    SELECT YEAR("2007-04-29") - YEAR("1979-05-20") - (RIGHT("2007-04-29", 5) < RIGHT("1979-05-20", 5)) AS age;
    Here's an explanation.

  8. #8
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great !!

    Ok what if i use this :

    $date1 = "12/22/1897";
    $date2 = "01/08/1999";

    if ($date1 > $date2)
    { echo "Date 2 is ELDER" ;}

    if ($date1 < $date2)
    { echo "Date 1 is ELDER" ;}

    I checked this its working. The only thing is that here we can set monthe like 13 and days like 32, for that i think we can have some check. Is there any other problem with this idea ? what u ppl think about it ?

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zeeshanhashmi View Post
    I checked this its working.
    No, it's not. It will work, if you write the date in ISO-format though.

  10. #10
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would u please enlighten the ISO Format. U must be thinking that i m asking FOOLISH questions, but actualy i am quite new to the programming.

    Thansk & Regsrds

  11. #11
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Saul

  12. #12
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Adodb_date may be helpful for you.
    It massively extends the date range workable by PHP

    http://phplens.com/phpeverywhere/adodb_date_library


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
  •