strtotime accepting invalid values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Thomson

    strtotime accepting invalid values

    I'm using strtotime to validate a date/time passed in from a form but
    am having some problems with it. It seems to allow invalid values,
    such as "2004-04-13 21:66:13".

    Does anyone know why this is? Is this a bug or a "feature"?

    I'm using PHP 4.3.2.

    TIA.

    Craig
  • ljb

    #2
    Re: strtotime accepting invalid values

    crtblog@mailina tor.com wrote:[color=blue]
    > I'm using strtotime to validate a date/time passed in from a form but
    > am having some problems with it. It seems to allow invalid values,
    > such as "2004-04-13 21:66:13".
    >
    > Does anyone know why this is? Is this a bug or a "feature"?
    >
    > I'm using PHP 4.3.2.[/color]

    strtotime() isn't very useful in PHP 4 for validating dates, as you found.
    It seems to try really hard to make some sense of any input, and can
    produce unexpected results. There are several bug reports on it, and I
    think there is a rewrite for PHP 5 to make it do more checks for invalid
    dates. But I'm not sure it will ever be really 'fixed' to validate
    date/time input, since it supports many input variations including relative
    date/times.

    For PHP 4, sometimes you can use regular expression matching to
    validate date input, if you're willing to restrict the acceptable input
    formats.

    Comment

    Working...