Handle multiple input date formats?

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Handle multiple input date formats?

    I have a date input field and I want to be able to handle 3/22/04,
    22-mar-04, March 22, 2004, etc. I looked through the Module List and
    there are dozens of Date/Time routines but no way to figure out which,
    if any, will do what I want.

    Clues for me please?
    fishfry Guest

  2. Similar Questions and Discussions

    1. cfcalendar date input into an input field
      Like a JS datepicker, how do i use cfcalendar to input a date into an input field? Something like this:...
    2. date formats
      hi i am working with uk date formats (dd/mm/yy) however the server the site is hosted on is in the us(mm/dd/yy) format i am using the following...
    3. Converting Date Formats?
      Howdy! I have some dates in a MySQL database that are in a 'Y-m-d' format. Is there a way to have PHP read these dates and convert them to a...
    4. Date formats in webpages
      I am new to using ASP and am trying to develop a site for the band I am a member of. The data for our bookings is held in an Access database and I...
    5. Formats, fields, input masks, et al
      Okay, I understand what you are saying, and the customer wants it, so the customer gets it. And you're right, even if you default the area code...
  3. #2

    Default Re: Handle multiple input date formats?

    fishfry wrote:
    > I have a date input field and I want to be able to handle 3/22/04,
    > 22-mar-04, March 22, 2004, etc. I looked through the Module List
    > and there are dozens of Date/Time routines but no way to figure out
    > which, if any, will do what I want.
    No way? Of course there is. One way is to browse the descriptions at
    [url]http://search.cpan.org/[/url].
    > Clues for me please?
    [url]http://search.cpan.org/perldoc?Date%3A%3AParse[/url]

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
    Gunnar Hjalmarsson Guest

  4. #3

    Default Re: Handle multiple input date formats?

    fishfry wrote:
    > I have a date input field and I want to be able to handle 3/22/04,
    Would this be the 22 of April in the year 2003 or the 22 of March in year
    2004?

    And you are lucky that there are no 22 months in the year. If you would have
    used e.g. 05 instead in your example, then this would be 3rd of May 2004 in
    most parts of the world.
    And of course this doesn't even begin to address the complexity of any but
    the Gregorian calender, e.g. the Hebrew calender, the Islamic calender, the
    Japanese imperial calender, etc, etc. are left out.

    If you allow a free form text field for date entry then the values you
    receive will be useless.
    > 22-mar-04, March 22, 2004, etc. I looked through the Module List and
    > there are dozens of Date/Time routines but no way to figure out which,
    > if any, will do what I want.
    >
    > Clues for me please?
    Familiarize yourself with date formats that people actually use and you will
    notice that an automatic "detection" ends up being an automated guess.

    _YOU_ must define and enforce the format or people will enter dates in any
    of dozens of ambiguous formats where no software or human can make a safe
    call. You could just as well use a rand(), that's easier to do.

    jue



    Jürgen Exner Guest

  5. #4

    Default Re: Handle multiple input date formats?

    Jürgen Exner wrote:
    > fishfry wrote:
    >> I have a date input field and I want to be able to handle
    >> 3/22/04,
    >
    > If you allow a free form text field for date entry then the values
    > you receive will be useless.
    >
    > _YOU_ must define and enforce the format or people will enter dates
    > in any of dozens of ambiguous formats where no software or human
    > can make a safe call.
    To the OP:
    Even if I chose to answer your question directly, I agree with Jürgen.
    What you are trying to do appears to be a bad idea.

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
    Gunnar Hjalmarsson Guest

  6. #5

    Default Re: Handle multiple input date formats?

    In article <BLOCKSPAMfishfry-EFAC67.03554711092004@netnews.comcast.net>,
    fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
    > I have a date input field and I want to be able to handle 3/22/04,
    >22-mar-04, March 22, 2004, etc. I looked through the Module List and
    >there are dozens of Date/Time routines but no way to figure out which,
    >if any, will do what I want.
    >
    I agree with suggestions to enforce the format but you
    may find Date::Manip useful for dealing with potential
    variability.

    For instance, if you specify "month day year", Date::Manip
    handles several variants:

    # perl -MDate::Manip -le 'print &ParseDate("3/22/04")'
    2004032200:00:00

    # perl -MDate::Manip -le 'print &ParseDate("March 22, 2004")'
    2004032200:00:00

    # perl -MDate::Manip -le 'print &ParseDate("mar-22-04")'
    2004032200:00:00

    perl -MDate::Manip -le 'print &ParseDate("03.22.04")'
    2004032200:00:00

    --
    Charles DeRykus


    Charles DeRykus Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139