Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a custom Drupal date format be added?

Tags:

How do you add a custom Drupal date format. I want to display the date without hours and minutes, but the options don't include it.

like image 422
vfclists Avatar asked Dec 04 '11 13:12

vfclists


People also ask

How do I change the date format in Drupal?

You can create a new date/time format using the standard PHP date/time formatting tokens by navigating to Admin > Configuration > Regional and Language > Date and Time and clicking on the Formats tab (admin/config/regional/date-time/formats).

When creating a custom date format What does the code DD specify?

Specifying a custom format DDDD DD would produce dates that show the Weekday and the Day, as shown below. Specifying a custom format yy-mm-dd (dddd) would produce dates in the format 18-01-04 (Thursday). Specifying a custom format "Q"1 YYYY would produce dates that show Q1 2018.

How do I get the current date in Drupal 8?

Get the date field programmatically $datetime = new DrupalDateTime($node->get('field_datetime')->value, 'UTC'); $date_formatter = \Drupal::service('date. formatter'); $date = $date_formatter->format($datetime->getTimestamp(), 'custom', 'Y-m-d H:i'); // For datetime fields you can also do this.


1 Answers

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.

Cheers, Vishal

Below is the image so that you know where it is.

Drupal Date and time "Formats" tab

like image 54
Vishal Khialani Avatar answered Oct 13 '22 00:10

Vishal Khialani