Answers.Body: <p>date_format is deprecated because strftime is deprecated in php 8. The problem with crmDate is the input has to be in ISO format, but it might not be depending on your site settings.</p>
  <p>But in smarty 3 you have the option of telling date_format to use the non-deprecated <code>date</code> instead of <code>strftime</code>, but note that the format specifiers <a href="https://www.php.net/manual/en/datetime.format.php" rel="nofollow noreferrer">are different</a> and do not have <code>%</code> in them. In fact that's how you tell it, by leaving out the <code>%</code>. So try <code>|date_format:&quot;j/m/Y&quot;</code>. <strong>EDIT</strong>: This should work but fails because there's still some intermediate code in core that ends up trying to load smarty2 date_format. If I hack <a href="https://github.com/civicrm/civicrm-core/blob/bcac045c1317be9be2a5db0c46bfd5354cd34985/CRM/Core/Smarty.php#L131" rel="nofollow noreferrer">this line</a> to instead be <code>$smartyDir = $pkgsDir . DIRECTORY_SEPARATOR . 'smarty4/vendor/smarty/smarty/libs' . DIRECTORY_SEPARATOR;</code> and then clear cache, then it works.</p>
  <p>Also by the way, for 5.72+ the recommended smarty is now v4: <a href="https://github.com/civicrm/civicrm-core/blob/bcac045c1317be9be2a5db0c46bfd5354cd34985/templates/CRM/common/civicrm.settings.php.template#L267" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/bcac045c1317be9be2a5db0c46bfd5354cd34985/templates/CRM/common/civicrm.settings.php.template#L267</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-06T17:37:33.043Z
Answers.Text: Changing the format string in `date_format` + changing one line in `wp-content/plugins/civicrm/civicrm/CRM/Core/Smarty.php` + clearing the cache with the command `wp cache flush` did the trick. Thank you.
Answers.UserDisplayName: Pierre François
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-06T17:39:11.877Z
Answers.Text: I have a question: will I have to change manually that one line in `wp-content/plugins/civicrm/civicrm/CRM/Core/Smarty.php` at each update of CiviCRM core?
Answers.UserDisplayName: Pierre François
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-06T18:24:55.120Z
Answers.Text: No it will need to be fixed in core. I made a ticket https://lab.civicrm.org/dev/core/-/issues/5130
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-23T19:54:18.987Z
Answers.Text: It looks like as of 5.73.0, Civi core has been updated so no "hack" is needed, right?
Answers.UserDisplayName: Noah Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-23T20:21:48.153Z
Answers.Text: Core itself replaced date_format in message templates a long time ago before knowing about the smarty3/4 feature. So this question only applies if you are using a customized message template that has date_format in it. If you do, then upon upgrading to 5.73, your options are: (1) Continue to use date_format, but you'll need to both switch to smarty 4, and update the format strings in your template to the non-% version. (2) Use crmDate, which in some locales doesn't parse the input properly, so won't output what you want. crmDate only works reliably when the input is ISO format.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-23T20:24:43.373Z
Answers.Text: But yes no hack to core code is needed in 5.73+.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-12T20:49:40.167Z
Answers.Text: Note that if you use `|crmDate` directly in the tokens (rather than in smarty variables) it will be working with a date that has not been formatted so the ISO format issues mentioned above would not apply
Answers.UserDisplayName: eileen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-06T15:17:35.627Z
Answers.LastActivityDate: 2024-04-06T15:47:42.263Z
Answers.LastEditDate: 2024-04-06T15:47:42.263Z
Answers.UserDisplayName: Demerit
Body: <p>Since I enabled Smarty 3 under CiviCRM 5.72, the messages containing dates followed by the <code>|date_format:&quot;%e/%m/%Y&quot;</code> modifier cause next error message to occur:</p>
  <blockquote>
  <p>There has been a critical error on this website.</p>
  </blockquote>
  <p>I tried to use the <code>|crmDate:&quot;%e/%m/%Y&quot;</code> modifier instead but I get the same error message.</p>
  <p>I wonder how I could format dates in my messages with Smarty 3, or shall I seriously have to downgrade to Smarty 2 forever?</p>
  
Tags: <civimail><dates><smarty3>
Title: date_format no longer works with Smarty 3 in messages
ThreadText: # date_format no longer works with Smarty 3 in messages
  
  (Asked by: username_0 on 2024-04-06)
  
  Since I enabled Smarty 3 under CiviCRM 5.72, the messages containing dates followed by the `|date_format:"%e/%m/%Y"` modifier cause next error message to occur:
  
  > There has been a critical error on this website.
  
  I tried to use the `|crmDate:"%e/%m/%Y"` modifier instead but I get the same error message.
  
  I wonder how I could format dates in my messages with Smarty 3, or shall I seriously have to downgrade to Smarty 2 forever?
  
  **Tags:** civimail, dates, smarty3
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-04-06. Score: 1 | Accepted answer
  
  date\_format is deprecated because strftime is deprecated in php 8. The problem with crmDate is the input has to be in ISO format, but it might not be depending on your site settings.
  
  But in smarty 3 you have the option of telling date\_format to use the non-deprecated `date` instead of `strftime`, but note that the format specifiers [are different](https://www.php.net/manual/en/datetime.format.php) and do not have `%` in them. In fact that's how you tell it, by leaving out the `%`. So try `|date_format:"j/m/Y"`. **EDIT**: This should work but fails because there's still some intermediate code in core that ends up trying to load smarty2 date\_format. If I hack [this line](https://github.com/civicrm/civicrm-core/blob/bcac045c1317be9be2a5db0c46bfd5354cd34985/CRM/Core/Smarty.php#L131) to instead be `$smartyDir = $pkgsDir . DIRECTORY_SEPARATOR . 'smarty4/vendor/smarty/smarty/libs' . DIRECTORY_SEPARATOR;` and then clear cache, then it works.
  
  Also by the way, for 5.72+ the recommended smarty is now v4: <https://github.com/civicrm/civicrm-core/blob/bcac045c1317be9be2a5db0c46bfd5354cd34985/templates/CRM/common/civicrm.settings.php.template#L267>
  
  > **Comments:**
  > **username_0**: Changing the format string in `date_format` + changing one line in `wp-content/plugins/civicrm/civicrm/CRM/Core/Smarty.php` + clearing the cache with the command `wp cache flush` did the trick. Thank you.  
  > **username_0**: I have a question: will I have to change manually that one line in `wp-content/plugins/civicrm/civicrm/CRM/Core/Smarty.php` at each update of CiviCRM core?  
  > **username_1**: No it will need to be fixed in core. I made a ticket https://lab.civicrm.org/dev/core/-/issues/5130  
  > **username_2**: It looks like as of 5.73.0, Civi core has been updated so no "hack" is needed, right?  
  > **username_1**: Core itself replaced date_format in message templates a long time ago before knowing about the smarty3/4 feature. So this question only applies if you are using a customized message template that has date_format in it. If you do, then upon upgrading to 5.73, your options are: (1) Continue to use date_format, but you'll need to both switch to smarty 4, and update the format strings in your template to the non-% version. (2) Use crmDate, which in some locales doesn't parse the input properly, so won't output what you want. crmDate only works reliably when the input is ISO format.  
  > **username_1**: But yes no hack to core code is needed in 5.73+.  
  > **username_3**: Note that if you use `|crmDate` directly in the tokens (rather than in smarty variables) it will be working with a date that has not been formatted so the ISO format issues mentioned above would not apply  
  
  ---
  
  