0

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

2 Answers 2

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

Pradeep

5
  • 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. Commented Mar 3, 2022 at 11:49
  • actually in your code it's thestrtotime that pertubates the sending of the e-mail :-( without it the e-mail is sent Commented Mar 3, 2022 at 13:11
  • Instead of the strtotime, this works for me (on unix, but not windows): {$end_date|date_format:"%s"}
    – Demerit
    Commented Mar 4, 2022 at 1:37
  • Thanks, @Demerit I have updated my answer with your suggestion. Commented Mar 4, 2022 at 11:09
  • To make things more interesting - date_format is deprecated in Civi with Smarty 3+. So you're back to using strtotime. Commented Feb 12 at 20:50
0

answer came later on:

{latestcurrentmembership.end_date-31536000|date_format:'%Y%m%d'}

I only add to subtract one year in seconds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.