Is there a Days Until function?

jhall95

Member
Have a campaign where they need to respond by the 20th of January so instead of changing the copy every day is there a macro to calculate the days until a date and can input that number?
 
{% set difference = date(date('21-1-20')).diff(date('now'|date('Y/m/d'))) %}{% set leftDays = difference.days %}{{leftDays}}

Can you explain the logic of this a bit?
Does this calculate how many days until 20 Jan?
i.e. if sent on 10 Jan, it would say 'there are 10 days left to take action' etc?
 
This will just return a number so to do your command above you would need:

"there are {% set difference = date(date('21-1-20')).diff(date('now'|date('Y/m/d'))) %}{% set leftDays = difference.days %}{{leftDays}} days left to take action"

Copy my code and put it in https://twigfiddle.com/ and mess around with the dates so you get a feel for it before adding it to any campaigns
 
Back
Top