How to Add a Custom Date Format in Drupal 8
In Drupal 8, the process of adding a new date format is substantially simpler than in Drupal 7.
In Drupal 7, there were several steps involved.
In Drupal 8, the process is substantially simpler:
- Go to Configuration > Date and time formats.
- You’ll see that Drupal 8 ships with around a dozen formats, compared with 3 in Drupal 7.
- Click the blue “Add format” button:
You can now add a date format directly into the “Format string” field.
You wil need to use the PHP syntax on this page. Drupal will give you a live preview of your date format:
Inside field in a content type, how to create a field only month y Year. thanks
Same question from my side, if you got your answer please reply
You are great
To create a format for only month and year, head over to Configuration -> Regional & Language -> Date formats. Click Add Format.
Jan-2020 would be M-Y
1-2020 would be n-Y
January-2020 would be F-Y
January/2020 would be F/Y
01-2020 would be m-Y
Check out https://www.php.net/manual/en/function.date.php for all the formats you can use.
Once the format is created, go to Structure -> Content Types -> Manage Display for the content type field you want to update. Click on the gear and select your new format.
I hope that helps.