Would be nice to be able to change the date format for the form display (when editing node). Currently in Drupal 8.0.1, you can only change it for manage display only (when node is viewed).

Personally, I don't like how I have to select my date in the form display (when editing node) and not able to just type it in like in Drupal 7.

PS: I haven't had the chance to test Drupal 8.0.2, which came out today, I highly doubt this feature was added.

CommentFileSizeAuthor
#21 date error.jpg12.28 KBimclean
#21 date example.jpg9.26 KBimclean

Comments

Camster created an issue. See original summary.

no sssweat’s picture

Version: 8.0.2 » 8.1.x-dev
no sssweat’s picture

Issue summary: View changes
mpdonadio’s picture

Not sure how this applies since it is an element, so it should be localized by your browser? Or are you on a browser like Firefox that uses the polyfill?

no sssweat’s picture

@mpdonadio You're right about the browser. In Chrome I cannot paste anything to there and brings up a Calendar widget, but with Firefox I can paste and there is no Calendar widget (which is nice IMO).

But... it would still be nice if we could custom format it.

Ex:

When editing or creating a node in D8 my date field is always stuck to this format http://i.stack.imgur.com/34pjR.jpg

Side note: I think I just discovered a bug, when mouse hover over it, it's giving an incorrect example. Year should be last... http://i.stack.imgur.com/34pjR.jpg

While in D7 I can customize it http://i.stack.imgur.com/HogyD.jpg and http://i.stack.imgur.com/Aa1jz.jpg. I can format it however I want using the date function http://php.net/manual/en/function.date.php. I could put M d, Y So I have the freedom to make that people have to type Feb 25, 2016 instead of 02/25/2016

no sssweat’s picture

Edited comment #5, just bumping this, so you get the notification, just in case you saw my original version.

swentel’s picture

Yeah, the HTML5 datefield isn't always great, or even user friendly in terms of format. Maybe we should allow selecting the html type ?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

webel’s picture

@Camster I agree, also want to be able to easily change the format for editing dates as one could in D7.

For example, the Drupal project/module page release dates sensibly use ordering-friendly YYYY-MM-DD, but the edit form for Date in Drupal8 seems to be fixed at dd/mm/yyy using a widget.

mpdonadio’s picture

These are input type=date elements, which don't have format specifiers per the spec.

I fear allowing users to specify the HTML type for these will get us closer to the do-it-all road.

I am leading towards keeping these the way they are in core, and having this be something the contrib space can handle, since it would just be swapping out the form widgets.

?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kclarkson’s picture

would also like to see this! There are so many different reasons why you may need to change the date format within the form.

This is a huge user experience improvement that would be helpful out of the box.

leisurman’s picture

Can the default date format Y/m/d be changed to m/d/Y in the edit form with a hook alter and what hook can be used?

mpdonadio’s picture

#14, yes and no. The widgets use the Datetime form element, which by default uses the HTML5 input elements. Those require the HTML5 date and time formats (Y-m-d and H:i:s). If you want a different format, you need make a new widget and change the types to text so you can specify your own format (but you lose the popups), or you can do this via a form_alter. Off the top of my head, I am not positive which form_id to target with the form_alter.

leisurman’s picture

In case anyone needs this

function mymodule_element_info_alter(array &$types) {

  // Set defaults for datetime fields.
  $types['datetime']['#process'][] = '_set_datetime_defaults';
}

/**
 * Set defaults for datetime fields.
 */
function _set_datetime_defaults($element) {
  // Add placeholders to all datetime fields.
$element['date']['#attributes']['data-drupal-date-format'] = ['m/d/Y'];
  $element['date']['#date_date_format'] = 'm/d/Y';
  $element['date']['#attributes']['placeholder'] = ["MM-DD-YYY"];
  $element['time']['#attributes']['placeholder'] = ["HH:MM:SS"];
  
  return $element;
}
rodrigoaguilera’s picture

@leisurman that code works fine for the ui part but date fields have validators that expect the HTML5 format on the backend.

I think we should do something similar to what is explained on this thread
http://stackoverflow.com/questions/27850791/input-type-date-format-and-d...

But I feel it should go into contrib with a new field formatter with its own config.

I don't know how can we have a interface to change the the date format of other widgets like the published date but that can probably can be handled in the contrib module.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

shaktik’s picture

Issue tags: +feature request

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

imclean’s picture

StatusFileSize
new9.26 KB
new12.28 KB

Here's a nice example of things simply not working. Using Drupal 8.4.x. and the core media module, I've added a standard "Date" field to a media entity. In Chrome, the field expects the input to be mm/dd/yyyy, which makes sense in my part of the world.

The field itself expects YYYY-MM-DD, which I wouldn't mind either. However, neither of these are configurable that I can see, resulting in an error.

imclean’s picture

Never mind, the date format wasn't the problem in my case, I needed to enter a time. It submitted fine in the specified format. I'd like to make the time optional but that's another issue.

imclean’s picture

andrezstar’s picture

#16 worked for me but then the form validation wont accept this format for InternetExplorer.
It does validate for other browsers tho...
Weird, isnt it?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dunebl’s picture

Priority: Normal » Major
Issue tags: -

#16 is no more working on D8.9.1
As an example for why this is not working, the key $element['date']['#attributes']['data-drupal-date-format'] used in the #16 code doesn't exists anymore.
I changed the priority into Major, because There is no way to change the format of the date widget.
Use case: European peoples working on English system/browser (which is very common) => they need a d/m/Y widget.
The only way I could solve this issue is to use the select list plugin

tawellman’s picture

I am running into a similar problem.

I have a use case where the user needs to be able to copy the date from another source and paste that value into the date field. It would be too time-consuming to have to pick the date from a "date picker" widget. It would be ok if it were a one-off situation but this user needs to be able to enter several at a time.

I agree that it would be extreemly helpful if a "Text Field" Widget was available again.

no sssweat’s picture

There are now contrib modules that will allow you to change it, see https://drupal.stackexchange.com/a/297000/27710

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Active » Closed (duplicate)
Issue tags: +Bug Smash Initiative
Related issues: +#2791693: Remove sample date from date field error message and title attribute

Discovered this while looking for duplicates, tagging Bug Smash Initiative.

There is a later issue, with more discussion and patch, for this problem. Although this is the earliest I have found closing this as a duplicate.

franxo’s picture

Hi all,
Just to comment on the workaround I have used to solve this, in case it helps someone.

Contrib module: Datetime Flatpickr (https://www.drupal.org/project/datetime_flatpickr)
Configuration for the Flatpickr datetime picker:
Alternative input format: d/m/Y
Date format: Y-m-d

Regards,