My Date in Twig is ignoring format












6















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



























    6















    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

























      6












      6








      6








      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 Jan 7 at 14:21









      David LozziDavid Lozzi

      5410




      5410






















          2 Answers
          2






          active

          oldest

          votes


















          8














          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
            Jan 7 at 15:19



















          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
            Jan 7 at 14:44








          • 2





            Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

            – David Lozzi
            Jan 7 at 15:28











          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









          8














          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
            Jan 7 at 15:19
















          8














          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
            Jan 7 at 15:19














          8












          8








          8







          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 Jan 7 at 14:41

























          answered Jan 7 at 14:33









          KevinKevin

          17.8k848108




          17.8k848108













          • This is much better than my answer!

            – hotwebmatter
            Jan 7 at 15:19



















          • This is much better than my answer!

            – hotwebmatter
            Jan 7 at 15:19

















          This is much better than my answer!

          – hotwebmatter
          Jan 7 at 15:19





          This is much better than my answer!

          – hotwebmatter
          Jan 7 at 15:19













          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
            Jan 7 at 14:44








          • 2





            Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

            – David Lozzi
            Jan 7 at 15:28
















          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
            Jan 7 at 14:44








          • 2





            Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

            – David Lozzi
            Jan 7 at 15:28














          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 Jan 7 at 14:30









          hotwebmatterhotwebmatter

          459112




          459112








          • 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
            Jan 7 at 14:44








          • 2





            Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

            – David Lozzi
            Jan 7 at 15:28














          • 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
            Jan 7 at 14:44








          • 2





            Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

            – David Lozzi
            Jan 7 at 15:28








          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
          Jan 7 at 14:44







          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
          Jan 7 at 14:44






          2




          2





          Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

          – David Lozzi
          Jan 7 at 15:28





          Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!

          – David Lozzi
          Jan 7 at 15:28


















          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.




          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

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]