Is there a field in Drupal 8 that lets you select a time without actually selecting a date? Or should you just use datetime?


3 Answers 3


You can use datetime element and disable date widget:

$widget['time_container']['time'] = [
  '#type' => 'datetime',
  '#title' => $this->t('Time'),
  '#size' => 20,
  '#date_date_element' => 'none', // hide date element 
  '#date_time_element' => 'time', // you can use text element here as well 
  '#date_time_format' => 'H:i'
  • It doesn't work for me, i got error on validation because Drupal validateDatetime are looking for $date = $input['object']; and in your case object is empty. Sep 10, 2019 at 13:03
  • you can use '#validated' => true to avoid issue in validation Sep 10, 2019 at 13:12

Depending on what you want to select time for, you may want to try HMS field.

The field stores values as integer. Both input and output can be formatted as Hours, Minutes and/or Seconds. Alter functions provide a way for developers to add their own format.

Please note that this is a great field for "time durations," but not so good if you are trying to capture a time of day with PM/AM.

Timefield was a good option for capturing just time of the day, BUT it has not been ported to Drupal 8.


Hi you can use https://www.drupal.org/project/time_field module. Easy and perfect fit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.