text input of date and timestamp fields

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

    text input of date and timestamp fields

    I'm working on a PHP frontend for a PostgreSQL db and I'm looking for the
    best way to create date or timestamp inputs. Let's take a date in the
    format yyyy-mm-dd as an example. This is too error prone, I know my users
    will do it wrong

    <input type="text" name="fieldname ">

    Right now I'm thinking about something like this:

    <input type="text" size="4" name="y_fieldna me">-
    <input type="text" size="2" name="m_fieldna me">-
    <input type="text" size="2" name="d_fieldna me">

    but this is IMO a very ugly solution, because after the SUBMIT I have to
    glue all the parts together before inserting the values into the db.
    Something like this:

    <input type="text" format="yyyy-mm-dd" name="fieldname ">

    would be ideal, but AFAIK this doesn't exist in HTML. Can anybody give me
    any tips? How did you solve this? Thanks!
  • Martin Lucas-Smith

    #2
    Re: text input of date and timestamp fields



    [color=blue]
    > I'm working on a PHP frontend for a PostgreSQL db and I'm looking for the
    > best way to create date or timestamp inputs. Let's take a date in the
    > format yyyy-mm-dd as an example. This is too error prone, I know my users
    > will do it wrong
    >
    > <input type="text" name="fieldname ">
    >
    > Right now I'm thinking about something like this:
    >
    > <input type="text" size="4" name="y_fieldna me">-
    > <input type="text" size="2" name="m_fieldna me">-
    > <input type="text" size="2" name="d_fieldna me">
    >
    > but this is IMO a very ugly solution, because after the SUBMIT I have to
    > glue all the parts together before inserting the values into the db.
    > Something like this:
    >
    > <input type="text" format="yyyy-mm-dd" name="fieldname ">
    >
    > would be ideal, but AFAIK this doesn't exist in HTML. Can anybody give me
    > any tips? How did you solve this? Thanks![/color]

    I have run up against the same problem, as there is indeed no way to do
    this in HTML.

    I've used three boxes, with gluing together, but used a select drop-down
    box instead of month, so there's then no question of which is the day and
    which is the month.

    I've also added a configurable option for year which allows users to enter
    two-figure dates instead of four (i.e. the interface accepts either and
    converts the actual database input accordingly, by appending 19 or 20
    depending on the set year cut-off point.


    Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22



    Comment

    • Joop

      #3
      Re: text input of date and timestamp fields

      On Thu, 23 Oct 2003 17:34:43 +0100, Martin Lucas-Smith wrote:
      [color=blue]
      > I have run up against the same problem, as there is indeed no way to do
      > this in HTML.
      >
      > I've used three boxes, with gluing together, but used a select drop-down
      > box instead of month, so there's then no question of which is the day
      > and which is the month.
      >
      > I've also added a configurable option for year which allows users to
      > enter two-figure dates instead of four (i.e. the interface accepts
      > either and converts the actual database input accordingly, by appending
      > 19 or 20 depending on the set year cut-off point.[/color]

      Thanks Martin. Well, I guess it's time to create some real ugly code :-)

      The naming of the fields is the ugliest part of it. The fieldnames in the
      frontend are dynamic (fields from a postgresql db), so I guess I will have
      to do naming like this

      fld_d_y_birthda y
      fld_d_m_birthda y
      fld_d_d_birthda y

      fld_t_y_takeoff
      fld_t_m_takeoff
      fld_t_d_takeoff
      fld_t_h_takeoff
      fld_t_M_takeoff
      fld_t_s_takeoff

      and my backend will have to parse the $_POST array twice. The first time
      to make whole values of the fld_d_* and fld_t_* elements. And a second
      time to create the SQL INSERT statement.

      Comment

      Working...