Date and Time Formats in Drupal 8

One of the questions we see regularly is "How do I change the date and time format in my views and posts?"  The most common issue we see is where you are just trying to display a date, but the time shows up even though you're not storing it!

In this tutorial, we'll show you how to set up Date and Time formats in Drupal 8.

You'll note that out of the box, Drupal 8 doesn't provide many date formats where the time is not included, so that if you've configured a date field to only use the date and not the time, Drupal will still display the time when using one of those formats.  In the illustration below, the date field is set a "Date Only" field type, however, the time is still showing in the display.

date time problem

Since the Date module is now part of core, a lot of the work is done for you.  Go to: Configuration -> Regional and Language -> Date and Time Formats.

date time configuration

Let's create a Date format that changes the above from Mon, 04/13/2020 - 12:00 to Monday, April 13th, 2020.

  1. Click Add Format
  2. For the name, enter Full Date - No Time
  3. Now we need to consult the PHP Date format documentation over at date time php net docs
  4. Scroll through the documentation noting that for the above display you'll need to enter the following: l, F jS, Y.  The characters you need are on the left and the explanation is on the right. (lower case L, F, lower case J, S and Y).
  5. Enter the above into the Format String field and click Add Format. date time add format
  6. Wherever you need this format to appear, you'll now update the Display for that field.  For instance, in our illustration above, you would head over to Structure -> Content Types -> Article -> Manage Display.  
  7. Click on the gear on the Date field and select your new time change format
  8. Click Update.
  9. You'll see the following on a node that uses that field. date time fixed

As you can see, with Drupal 8, creating date and time formats for any use case scenario is quick and easy once you know where to look!

About the author

Rod holds two masters degrees and has been training people how to do "things" for over 25 years. Originally from Australia, he grew up in Canada and now resides just outside Cincinnati, Ohio.