My Date in Twig is ignoring format












2














I have a twig file with the following code in my Drupal 8.4.4 site:



<div class="value col-md-12">{{ node.field_date.value }}</div>



And in my content type, manage display option, I have it formatted like this:
enter image description here



But on the website, it shows the date as



2019-01-16T23:00:00



What am I missing?










share|improve this question



























    2














    I have a twig file with the following code in my Drupal 8.4.4 site:



    <div class="value col-md-12">{{ node.field_date.value }}</div>



    And in my content type, manage display option, I have it formatted like this:
    enter image description here



    But on the website, it shows the date as



    2019-01-16T23:00:00



    What am I missing?










    share|improve this question

























      2












      2








      2







      I have a twig file with the following code in my Drupal 8.4.4 site:



      <div class="value col-md-12">{{ node.field_date.value }}</div>



      And in my content type, manage display option, I have it formatted like this:
      enter image description here



      But on the website, it shows the date as



      2019-01-16T23:00:00



      What am I missing?










      share|improve this question













      I have a twig file with the following code in my Drupal 8.4.4 site:



      <div class="value col-md-12">{{ node.field_date.value }}</div>



      And in my content type, manage display option, I have it formatted like this:
      enter image description here



      But on the website, it shows the date as



      2019-01-16T23:00:00



      What am I missing?







      datetime






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      David Lozzi

      329




      329






















          2 Answers
          2






          active

          oldest

          votes


















          4














          You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).



          Do this instead:



          {{ content.field_date }}



          This will render normally and ensure field formatter settings are respected.






          share|improve this answer























          • This is much better than my answer!
            – hotwebmatter
            6 mins ago



















          1














          Try piping the value to twig's date function:



          https://twig.symfony.com/doc/2.x/filters/date.html



          That approach might give you something like this:



          <div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>





          share|improve this answer

















          • 1




            I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
            – Kevin
            41 mins ago













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "220"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f274744%2fmy-date-in-twig-is-ignoring-format%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).



          Do this instead:



          {{ content.field_date }}



          This will render normally and ensure field formatter settings are respected.






          share|improve this answer























          • This is much better than my answer!
            – hotwebmatter
            6 mins ago
















          4














          You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).



          Do this instead:



          {{ content.field_date }}



          This will render normally and ensure field formatter settings are respected.






          share|improve this answer























          • This is much better than my answer!
            – hotwebmatter
            6 mins ago














          4












          4








          4






          You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).



          Do this instead:



          {{ content.field_date }}



          This will render normally and ensure field formatter settings are respected.






          share|improve this answer














          You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).



          Do this instead:



          {{ content.field_date }}



          This will render normally and ensure field formatter settings are respected.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 44 mins ago

























          answered 52 mins ago









          Kevin

          17.5k848108




          17.5k848108












          • This is much better than my answer!
            – hotwebmatter
            6 mins ago


















          • This is much better than my answer!
            – hotwebmatter
            6 mins ago
















          This is much better than my answer!
          – hotwebmatter
          6 mins ago




          This is much better than my answer!
          – hotwebmatter
          6 mins ago













          1














          Try piping the value to twig's date function:



          https://twig.symfony.com/doc/2.x/filters/date.html



          That approach might give you something like this:



          <div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>





          share|improve this answer

















          • 1




            I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
            – Kevin
            41 mins ago


















          1














          Try piping the value to twig's date function:



          https://twig.symfony.com/doc/2.x/filters/date.html



          That approach might give you something like this:



          <div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>





          share|improve this answer

















          • 1




            I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
            – Kevin
            41 mins ago
















          1












          1








          1






          Try piping the value to twig's date function:



          https://twig.symfony.com/doc/2.x/filters/date.html



          That approach might give you something like this:



          <div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>





          share|improve this answer












          Try piping the value to twig's date function:



          https://twig.symfony.com/doc/2.x/filters/date.html



          That approach might give you something like this:



          <div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 55 mins ago









          hotwebmatter

          457112




          457112








          • 1




            I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
            – Kevin
            41 mins ago
















          • 1




            I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
            – Kevin
            41 mins ago










          1




          1




          I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
          – Kevin
          41 mins ago






          I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
          – Kevin
          41 mins ago




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Drupal Answers!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f274744%2fmy-date-in-twig-is-ignoring-format%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'