1

I am new to Drupal. I want to display event date like,

"28/07/2016 | 02 PM to 04 PM"

Default date formats display date like,

"28/07/2016 - 02 PM to 28/07/2016 - 04 PM"

How can I create such custom display format?

3
  • This could be a duplicate of stackoverflow.com/questions/8375674/…\
    – Cool
    Jul 28, 2016 at 8:48
  • Do you mean you are using 2 date fields for saving the start and end time?
    – Jimmy Ko
    Jul 28, 2016 at 9:34
  • yes @JimmyKo . I am using one field for date and 2 fields for start and end time respectively. I want it to be displayed it as One date value and two time values showing start and end time Jul 28, 2016 at 10:09

2 Answers 2

3

Do the following:

  1. Administration » Configuration » Regional and language » Date and Time

  2. There you will see a tab for format.

  3. Create a new format string "Y-M-d".

  4. Make this as your default for all date fields and you won't see the seconds any more.

  5. You don't need the date module for basic formatting.

UPDATE: From following comment,

If you want optional End time, use Timefield module

Timefield is a Field API field for storing simple non-timezone time values, with an optional end time, utilizing a simple JQuery timepicker widget for input.

4
  • Thank you for response @Arun. I don't want date to be displayed like Y-M-d or anything like that. I want to display date in the form of d-M-Y | start time - end time for example "28/07/2016 | 03 PM to 05 PM". Creating a new date format allows me to change order of date, month and year. How can I display time slots without repetition of date Jul 28, 2016 at 9:05
  • Did you try this module drupal.org/project/timefield. This module will allow you to define time with End time.
    – Cool
    Jul 28, 2016 at 9:09
  • Issue got fixed?
    – Cool
    Jul 28, 2016 at 10:54
  • Yes @Arun. I used one field for date and this time field module took care of time duration. So, I got what I was looking for. Thank you :) Jul 28, 2016 at 11:58
0

Using hook_date_formats() you can create date format

Example:

function app_common_date_formats() {
  $formats = array();
  $formats[] = array(
    'type'    => 'test_custom_date_format',
    'format'  => 'd-M-Y',
    'locales' => array(), );
  foreach ($formats as $format) {
    variable_set('date_format_' . $format['type'], $format['format']);
  }
return $formats;

}

1
  • Hi @Fawwad, Thank you for response. I got your point, this code will create a date format in the form of d-M-Y.How can I get display format like "d-M-Y | 02 PM to 04 PM"? Jul 28, 2016 at 9:01

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .