-1

In my custom module, I converted time from database like ('17:00:00') with format_date(). After I converted this I got a wrong time (17:10). Please check my code, I am also naive drupal develper.

$form['departure_time'] = array(
  '#type' => 'textfield',
  '#maxlength' => 10, 
  '#title' => t('Departure Time'),  
  '#default_value' => format_date(strtotime($data -> departure_time),'custom', 'H:m'),
  '#description' => t("You Need To Add Departure Time.<< 00:00"),
  '#required' => TRUE,
);

2 Answers 2

0

As listed in the documentation http://php.net/manual/en/function.date.php lowercase m is for month. For minutes you should use i.

$dep= format_date(strtotime($data -> departure_time),'custom', 'H:i'); 
0
0

Just of note, you don't need to pass the date through t() as format_date() handles this itself through _format_date_callback() for reference. You just have to pass in the langcode yourself.

2
  • This could have been a comment or a suggested edit to the answer
    – Pere
    Oct 13, 2014 at 11:43
  • It's a completely different comment, not related to the accepted answer post - it's optional and more about coding standards than how to solve the posters issue. If I were to add something related, it'd be more to do with that it's fairly clumsy to ask for a date via a textfield - a select box is a much better (and safer option).
    – Pobtastic
    Oct 13, 2014 at 12:33

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.