Grow your CSS skills. Land your dream job.

Birth minus 100 years bug?

  • # September 20, 2012 at 7:35 am

    So this is my code:

    $birth = ‘1994-09-18′;
    $birth_minus_100 = date(‘Y-m-d’, strtotime(‘- 100 year’, strtotime($birth)));

    It work fine when I substract 2 years or so, with 100 the result is 1970-01-01. It seems to me some PHP bug no?

    # September 20, 2012 at 8:09 am

    A timestamp is the number of seconds elapsed since January, 1st, 1970.
    So any date before then won’t exist (in timestamp terms)

    You should use a different date/time format for going back that far.

    __
    # September 20, 2012 at 8:45 pm

    Use the DateTime class.

    You shouldn’t have a problem unless you need to go back more than 292 billion years. : )

    To answer your question about it being a “bug,” no, it’s not a bug. It’s a known limitation with unix timestamps, and it’s not specific to PHP.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".