By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

text input of date and timestamp fields

P: n/a
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_fieldname">-
<input type="text" size="2" name="m_fieldname">-
<input type="text" size="2" name="d_fieldname">

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!
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


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_fieldname">-
<input type="text" size="2" name="m_fieldname">-
<input type="text" size="2" name="d_fieldname">

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!


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
www.lucas-smith.co.uk
Jul 17 '05 #2

P: n/a
On Thu, 23 Oct 2003 17:34:43 +0100, Martin Lucas-Smith wrote:
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.


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_birthday
fld_d_m_birthday
fld_d_d_birthday

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.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.