tags:

views:

351

answers:

2

In creating a drupal form, one can easily create a date field.

'#type' => 'date',

But what about a time field? Is there an easy way to create and use a drupal form field type that describes the time of day? (Something more elegant than just a textfield with the label "time"?)

+3  A: 

Actually, the date field is nothing more than a textfield with a label. That is on the outside. What you do get when using this field from the date module, is a lot of date validation, to make sure that what the user has typed/selected makes sense. The other thing you get is some different javascript tools to aid the typing of the actual date. But to do this, you need the data module.

Since time is a lot more simple (universal) than a date, you wont need much validation. So all you need, to make it into a fancy time field, is to add some javascript to help out, but this is not really needed.

So the short answer is no, you can't do something like that, but you don't really need to either. You could create your own time field with hook_elements() though if you really wanted to.

googletorp
Furthermore, if you are after something GUI, [Timepickr](http://haineault.com/media/jquery/ui-timepickr/page/) attaches to textfields.
Grayside
Great explanation. The hook_elements() concept is just what I was looking for.
Dan
+2  A: 

There does not seem to be a 'standard' solution for this at the moment, but you might find something useful in the following:

And while not exactly providing a time field, you might also be interested in the duration modules, depending on what you want to achieve.

Henrik Opel
Fantastic links. The example code and the duration module are excellent insights on the kinds of things that I want to do with a time field.
Dan
+1 ...now that I have acquired more than 15 rep. ;)
Dan
@Dan: Thanks - I often forget that restriction ;)
Henrik Opel

related questions