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.
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).
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.
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.
Do the following:
Administration » Configuration » Regional and language » Date and Time
There you will see a tab for format.
Create a new format string "Y-M-d".
Make this as your default for all date fields and you won't see the seconds any more.
You don't need the date module for basic formatting.
Cheers, Vishal
Below is the image so that you know where it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With