Answers.Body: <p>If you want 28 February 2019
  {foreach from=$contributions item=contribution} {assign
      var="date" value=$contribution.receive_date|date_format:"%d %B %Y"}</p>
  
  <p>If you want 28 02 2019
  {foreach from=$contributions item=contribution} {assign
      var="date" value=$contribution.receive_date|date_format:"%d %m %Y"}</p>
  
  <p>If you want it to look better (28/02/2019) you can add slashes value=$contribution.receive_date|date_format:"%d/%m/%Y"}</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-01T09:07:12.997Z
Answers.Text: Thank you for your quick answer ! Am I supposed to put this code directly in the template (so in the civi interface) or in a file ?
Answers.UserDisplayName: Davum
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-01T16:23:01.867Z
Answers.Text: Correct, put it in the template. Admin > Communications > Message Templates. I assume there is already some Smarty code there. You will likely just need to edit that code to include the last part |date_format...
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-04T10:10:01.017Z
Answers.Text: Thank you for your answer again. I put the code ("|date_format...") in the message template, but it displays "{contribution.receipt_date|date_format:"%d %m %Y"}" when I generate the PDF instead of the value of the date. It's like it wasn't able to understand the smarty code... even though we're using smarty in other templates and it works properly. Have you any ideas of what I could have probably forgotten ?
Answers.UserDisplayName: Davum
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-04T18:15:59.323Z
Answers.Text: Where you have {contribution.receipt_date|date_format:"%d %m %Y"} should just have {date} the smarty is further up on your template. Look for something like {foreach from=$contributions item=contribution} {assign var="date" value=$contribution.receive_date} and add/edit the |date_format:"%d %m %Y"
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-05T01:51:45.163Z
Answers.Text: I think part of the confusion here is that {contribution.receipt_date}, i.e. `"recei*pt*" and without the $ sign`, is a *token* and smarty modifiers won't work on it, whereas {$contribution.receive_date}, i.e. `"recei*v*e" and with the $ sign`, is a *variable* available for use in the template, which you can use smarty modifiers on.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-28T13:54:06.490Z
Answers.LastActivityDate: 2019-03-04T18:18:37.807Z
Answers.LastEditDate: 2019-03-04T18:18:37.807Z
Answers.UserDisplayName: Iowa Boy
Answers.Body: <p>As of CiviCRM 5.43, there is a much simpler answer:</p>
  <pre><code>{contribution.receipt_date|crmDate:&quot;shortdate&quot;}
  </code></pre>
  <p>There is <a href="https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#date" rel="nofollow noreferrer">full documentation</a> for the <code>crmDate</code> filter.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-11T16:24:48.633Z
Answers.LastActivityDate: 2022-05-11T16:24:48.633Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>You will need to have Smarty template processing turned on for mailings: make sure <code>CIVICRM_MAIL_SMARTY</code> is defined in your civicrm.settings.php file, as described in the <a href="https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#smarty" rel="nofollow noreferrer">CiviCRM User Guide</a>.</p>
  <p>Then, replace the <code>{contribution.receive_date}</code> token in your message with Smarty code such as this:</p>
  <ul>
  <li><p>For a date like &quot;26/01/2020&quot; (dd/mm/yyyy):</p>
  <p><code>{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%d/%m/%Y{/capture}{$formattableDateReceived|date_format:$formatString}</code></p>
  </li>
  <li><p>For a date like &quot;December 7, 2020&quot;:</p>
  <p><code>{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%B %e, %Y{/capture}{$formattableDateReceived|date_format:$formatString|strip}</code></p>
  </li>
  <li><p>For a date like &quot;01/26/2020&quot; (mm/dd/yyyy):</p>
  <p><code>{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%m/%d/%Y{/capture}{$formattableDateReceived|date_format:$formatString}</code></p>
  </li>
  <li><p>For a date like &quot;1/26/2020&quot; (m/d/yyyy):</p>
  <p><code>{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%m/%d/%Y{/capture}{capture assign=mdyCleanupFind}#(^|/)0#{/capture}{capture assign=mdyCleanupReplace}$1{/capture}{$formattableDateReceived|date_format:$formatString|regex_replace:$mdyCleanupFind:$mdyCleanupReplace}</code></p>
  </li>
  </ul>
  <p>These four examples use Smarty's <a href="https://www.smarty.net/docsv2/en/language.modifier.date.format.tpl" rel="nofollow noreferrer">date_format</a>, <a href="https://www.smarty.net/docsv2/en/language.modifier.strip.tpl" rel="nofollow noreferrer">strip</a> and <a href="https://www.smarty.net/docsv2/en/language.modifier.regex.replace.tpl" rel="nofollow noreferrer">regex_replace</a> modifiers. Due to the way that Civi applies Smarty to thank-you letters (as of Civi 5.32), we have to capture the parameters for each of these modifiers in a variable before using them.</p>
  <p>The patterns above should work for other date fields as well (receipt_date, cancel_date etc.)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-26T07:33:46.260Z
Answers.Text: To further explain why we can't give arguments to the Smarty modifiers directly as quoted strings: as of Civi 5.32, in CRM_Contribute_Form_Task_PDFLetterCommon::resolveTokens, the Smarty compiler is only called after Civi has already HTML-ified all the quotes within our Smarty tags, breaking them completely.
Answers.UserDisplayName: Noah Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-20T17:40:52.053Z
Answers.Text: this worked for me! thanks!
Answers.UserDisplayName: PTP Mark
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-26T07:19:43.047Z
Answers.LastActivityDate: 2021-01-26T07:19:43.047Z
Answers.UserDisplayName: Noah Miller
Answers.Body: <p>This code helped me to include an European date format into PDF-invoices:</p>
  <p><code>{$invoice_date|date_format:&quot;%d.%m.%Y&quot;}</code></p>
  <p>in your case you have to change invoice_date with the desired contribution.receipt_date</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-03T18:30:04.487Z
Answers.Text: Note that in php 8.1 this is deprecated because date_format uses strftime(). At some point you'll need to switch to crmDate as other answers indicate.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-03T16:21:07.297Z
Answers.LastActivityDate: 2022-11-03T16:21:07.297Z
Answers.UserDisplayName: wintermoor
Body: <p>I'm using the "Thank-you letters - print or email" functionality to generate a receipt for contributions. I created a new template with all the information needed. However we have a problem to display the receipt date at the correct format. Actually, when I chose the token "Receipt date" in the combobox, Civi inserts {contribution.receipt_date} in my template, and when I generate a PDF, it displays the date with the hours : for example, "2019-02-25 16:01:00". We would just like to display the date (without the hours) at this format : dd/mm/YYYY (for example : "25/02/2019"). I tried to add code like "date_format" in the source of the template to change the date format, but it didn't work. Is there an easy way to change it ?</p>
  
  <p>Thanks !</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-26T14:52:48.597Z
Comments.Text: I follow your guide but the date it gives me is today date and not the receive_date...
  Any suggest? Thank you
Comments.UserDisplayName: Angela
Tags: <receipts><dates>
Title: How to change the date format for the receipt date in a template
ThreadText: # How to change the date format for the receipt date in a template
  
  (Asked by: username_0 on 2019-02-28)
  
  I'm using the "Thank-you letters - print or email" functionality to generate a receipt for contributions. I created a new template with all the information needed. However we have a problem to display the receipt date at the correct format. Actually, when I chose the token "Receipt date" in the combobox, Civi inserts {contribution.receipt\_date} in my template, and when I generate a PDF, it displays the date with the hours : for example, "2019-02-25 16:01:00". We would just like to display the date (without the hours) at this format : dd/mm/YYYY (for example : "25/02/2019"). I tried to add code like "date\_format" in the source of the template to change the date format, but it didn't work. Is there an easy way to change it ?
  
  Thanks !
  
  **Tags:** receipts, dates
  
  > **Comments:**
  > **username_1**: I follow your guide but the date it gives me is today date and not the receive_date... Any suggest? Thank you  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2019-02-28. Score: 6
  
  If you want 28 February 2019
  {foreach from=$contributions item=contribution} {assign
  var="date" value=$contribution.receive\_date|date\_format:"%d %B %Y"}
  
  If you want 28 02 2019
  {foreach from=$contributions item=contribution} {assign
  var="date" value=$contribution.receive\_date|date\_format:"%d %m %Y"}
  
  If you want it to look better (28/02/2019) you can add slashes value=$contribution.receive\_date|date\_format:"%d/%m/%Y"}
  
  > **Comments:**
  > **username_0**: Thank you for your quick answer ! Am I supposed to put this code directly in the template (so in the civi interface) or in a file ?  
  > **username_2**: Correct, put it in the template. Admin > Communications > Message Templates. I assume there is already some Smarty code there. You will likely just need to edit that code to include the last part |date_format...  
  > **username_0**: Thank you for your answer again. I put the code ("|date_format...") in the message template, but it displays "{contribution.receipt_date|date_format:"%d %m %Y"}" when I generate the PDF instead of the value of the date. It's like it wasn't able to understand the smarty code... even though we're using smarty in other templates and it works properly. Have you any ideas of what I could have probably forgotten ?  
  > **username_2**: Where you have {contribution.receipt_date|date_format:"%d %m %Y"} should just have {date} the smarty is further up on your template. Look for something like {foreach from=$contributions item=contribution} {assign var="date" value=$contribution.receive_date} and add/edit the |date_format:"%d %m %Y"  
  > **username_3**: I think part of the confusion here is that {contribution.receipt_date}, i.e. `"recei*pt*" and without the $ sign`, is a *token* and smarty modifiers won't work on it, whereas {$contribution.receive_date}, i.e. `"recei*v*e" and with the $ sign`, is a *variable* available for use in the template, which you can use smarty modifiers on.  
  
  ---
  
  ### Answer by username_4 on 2022-05-11. Score: 3
  
  As of CiviCRM 5.43, there is a much simpler answer:
  {contribution.receipt_date|crmDate:"shortdate"}
  
  There is full documentation for the crmDate filter.
  
  
  ---
  
  ### Answer by username_5 on 2021-01-26. Score: 2
  
  You will need to have Smarty template processing turned on for mailings: make sure `CIVICRM_MAIL_SMARTY` is defined in your civicrm.settings.php file, as described in the [CiviCRM User Guide](https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#smarty).
  
  Then, replace the `{contribution.receive_date}` token in your message with Smarty code such as this:
  
  * For a date like "26/01/2020" (dd/mm/yyyy):
  
    `{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%d/%m/%Y{/capture}{$formattableDateReceived|date_format:$formatString}`
  * For a date like "December 7, 2020":
  
    `{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%B %e, %Y{/capture}{$formattableDateReceived|date_format:$formatString|strip}`
  * For a date like "01/26/2020" (mm/dd/yyyy):
  
    `{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%m/%d/%Y{/capture}{$formattableDateReceived|date_format:$formatString}`
  * For a date like "1/26/2020" (m/d/yyyy):
  
    `{capture assign=formattableDateReceived}{contribution.receive_date}{/capture}{capture assign=formatString}%m/%d/%Y{/capture}{capture assign=mdyCleanupFind}#(^|/)0#{/capture}{capture assign=mdyCleanupReplace}$1{/capture}{$formattableDateReceived|date_format:$formatString|regex_replace:$mdyCleanupFind:$mdyCleanupReplace}`
  
  These four examples use Smarty's [date\_format](https://www.smarty.net/docsv2/en/language.modifier.date.format.tpl), [strip](https://www.smarty.net/docsv2/en/language.modifier.strip.tpl) and [regex\_replace](https://www.smarty.net/docsv2/en/language.modifier.regex.replace.tpl) modifiers. Due to the way that Civi applies Smarty to thank-you letters (as of Civi 5.32), we have to capture the parameters for each of these modifiers in a variable before using them.
  
  The patterns above should work for other date fields as well (receipt\_date, cancel\_date etc.)
  
  > **Comments:**
  > **username_5**: To further explain why we can't give arguments to the Smarty modifiers directly as quoted strings: as of Civi 5.32, in CRM_Contribute_Form_Task_PDFLetterCommon::resolveTokens, the Smarty compiler is only called after Civi has already HTML-ified all the quotes within our Smarty tags, breaking them completely.  
  > **username_6**: this worked for me! thanks!  
  
  ---
  
  ### Answer by username_7 on 2022-11-03. Score: 0
  
  This code helped me to include an European date format into PDF-invoices:
  
  `{$invoice_date|date_format:"%d.%m.%Y"}`
  
  in your case you have to change invoice\_date with the desired contribution.receipt\_date
  
  > **Comments:**
  > **username_3**: Note that in php 8.1 this is deprecated because date_format uses strftime(). At some point you'll need to switch to crmDate as other answers indicate.  
  
  ---
  
  