Answers.Body: <p>answer came later on:</p>
  <blockquote>
  <p>{latestcurrentmembership.end_date-31536000|date_format:'%Y%m%d'}</p>
  </blockquote>
  <p>I only add to subtract one year in seconds</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-10T15:28:13.067Z
Answers.LastActivityDate: 2023-05-10T15:28:13.067Z
Answers.UserDisplayName: Guillaume Sorel
Answers.Body: <pre><code>{capture assign=&quot;end_date&quot;}{latestcurrentmembership.end_date}{/capture}
  
  // convert it to strtotime
  {assign var='end_date' value=$end_date|strtotime}
  
  or 
  
  {assign var='end_date' value=$end_date|date_format:&quot;%s&quot;}
  
  // display in date format 
  {$end_date|date_format:'%Y%m%d'}
  </code></pre>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-03T11:49:12.197Z
Answers.Text: this doesn't work, the pdf is triggered with a CiviRule based on a Tag and we can't even tick the check box without getting an error.  Smarty is on '1' in settings. Do I need anything else in the configuration? We've tried other operations and they were effective.
  what you wrote is one of the variations we tried unsuccessfully.
Answers.UserDisplayName: Guillaume Sorel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-03T13:11:20.487Z
Answers.Text: actually in your code it's the`strtotime` that pertubates the sending of the e-mail :-( without it the e-mail is sent
Answers.UserDisplayName: Guillaume Sorel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-04T01:37:53.077Z
Answers.Text: Instead of the `strtotime`, this works for me (on unix, but not windows): `{$end_date|date_format:"%s"}`
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-04T11:09:09.733Z
Answers.Text: Thanks, @Demerit I have updated my answer with your suggestion.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-12T20:50:17.903Z
Answers.Text: To make things more interesting - `date_format` is deprecated in Civi with Smarty 3+.  So you're back to using `strtotime`.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-03T11:31:47.947Z
Answers.LastActivityDate: 2022-03-04T11:08:26.190Z
Answers.LastEditDate: 2022-03-04T11:08:26.190Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I need to calculate a date based on a membership but this has to done with timestamp to have a common numeric value.
  We've read almost the whole smarty.net documentation and couldn't find our solution.</p>
  <p>This would have been our best trick:</p>
  <p><code>{capture assign=&quot;end_date&quot;}{latestcurrentmembership.end_date}{/capture}{$fin = $end_date|strtotime}</code></p>
  <p>but either <code>capture assign</code> and <code>strtotime</code> seem to be working within CiviCRM.
  Any idea?</p>
  <p>EDIT 1: <code>capture assign</code> works well, it's <code>strtotime</code> that seems to not work within CiviCRM</p>
  
Tags: <smarty>
Title: Is there way to convert date into timestamp with smarty
ThreadText: # Is there way to convert date into timestamp with smarty
  
  (Asked by: username_0 on 2022-03-03)
  
  I need to calculate a date based on a membership but this has to done with timestamp to have a common numeric value.
  We've read almost the whole smarty.net documentation and couldn't find our solution.
  
  This would have been our best trick:
  
  `{capture assign="end_date"}{latestcurrentmembership.end_date}{/capture}{$fin = $end_date|strtotime}`
  
  but either `capture assign` and `strtotime` seem to be working within CiviCRM.
  Any idea?
  
  EDIT 1: `capture assign` works well, it's `strtotime` that seems to not work within CiviCRM
  
  **Tags:** smarty
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-05-10. Score: 0 | Accepted answer
  
  answer came later on:
  
  > {latestcurrentmembership.end\_date-31536000|date\_format:'%Y%m%d'}
  
  I only add to subtract one year in seconds
  
  
  ---
  
  ### Answer by username_1 on 2022-03-03. Score: 2
  
  ```
  {capture assign="end_date"}{latestcurrentmembership.end_date}{/capture}
  
  // convert it to strtotime
  {assign var='end_date' value=$end_date|strtotime}
  
  or 
  
  {assign var='end_date' value=$end_date|date_format:"%s"}
  
  // display in date format 
  {$end_date|date_format:'%Y%m%d'}
  
  ```
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: this doesn't work, the pdf is triggered with a CiviRule based on a Tag and we can't even tick the check box without getting an error.  Smarty is on '1' in settings. Do I need anything else in the configuration? We've tried other operations and they were effective. what you wrote is one of the variations we tried unsuccessfully.  
  > **username_0**: actually in your code it's the`strtotime` that pertubates the sending of the e-mail :-( without it the e-mail is sent  
  > **username_2**: Instead of the `strtotime`, this works for me (on unix, but not windows): `{$end_date|date_format:"%s"}`  
  > **username_1**: Thanks, @username_2 I have updated my answer with your suggestion.  
  > **username_3**: To make things more interesting - `date_format` is deprecated in Civi with Smarty 3+.  So you're back to using `strtotime`.  
  
  ---
  
  