#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189

    Looking for strtotime() replacement


    I have a need for a function or class that works LIKE strtotime(), but I need to modify the way it works a little.

    So for starters I'm trying to find if anyone has reinvented this particular wheel.
    Thomas Tremain
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,072
    Rep Power
    9398
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    My application has to do with animals. Recording the birth date.
    Sometimes the entire date is known, sometimes just a year, or a year and a month.



    Three changes I need to make.

    1) output should be in Y-m-d format (which will be more self explanitary with ther next requirement)

    2) Needs to be able to handle incomplete dates differently.. "February 2013" should be saved as "2013-02-00" not "2013-02-01" because the actual day is unknown. Same with months if only the year is known.

    3) the current function translates "2012" as today at 10:12 PM, instead I want it recognized as a number.

    optional, the time of day is irrelevant, so I can drop that completely...

    Sure, I could just supply dropdown boxes for year, month and day, but I would really like to just offer a free form text box to the user.
    Thomas Tremain
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,072
    Rep Power
    9398
    I suggest you start looking for an alternative. strtotime() is complicated - it has a whole parser and lexer, treating the date string like it were a language with a grammar and syntax*.

    1. See date
    2. Difficult
    3. If the input is strictly a number then assume it's a year

    Web users who have done anything with dates are used to seeing (a) calendars or (b) separate boxes for each field. Nothing wrong with following the norm.
    Especially since strtotime() has some formats it won't recognize correctly (D/M/Y versus M/D/Y being the prime example), and that's despite how awesome it is at everything else. Without spending an inordinate amount of time on this, you won't get the same level of quality with your own version.

    * This means it's not simply a matter of editing code to adapt it to your own rules. Translating it to PHP is inadvisable because the parser paradigm isn't that great when it's interpreted at runtime, not to mention being a laborious chore.

IMN logo majestic logo threadwatch logo seochat tools logo