8 August 2013

This example shows you how to create time field using date module and Field API in Drupal.

Source code viewer
  1. function HOOK_admin_form() {
  2. $form = array();
  3.  
  4. // You need date module to use this field type.
  5. $form['HOOK_time'] = array(
  6. '#type' => 'date_text',
  7. '#title' => t('Time'),
  8. '#date_format' => 'H:i',
  9. '#date_increment' => 1,
  10. '#default_value' => array('date' => date('Y-m-d') . ' ' . variable_get('HOOK_time', '00:00')),
  11. );
  12.  
  13. return system_settings_form($form);
  14. }
Programming Language: PHP