Search code examples
phpprestashopprestashop-1.6smarty3

Calculate the difference between two dates in smarty 3 template prestashop


I have to calculate a sale end time relative to today,

I have the sale end time variable in this format {%d/%m/%Y %H:%M:%S} e.g.:(31/07/2016 18:27:58).

What I'm trying to do is to show ends: 8 days 06:10:29.
I can't use php code in the template because I'm using smarty 3 and I'm not an expert in smarty.


Solution

  • Change your date1 and date2 values

    {assign var="date1" value= $smarty.now}
    {assign var="date2" value= $smarty.now+20*24*60*60}
    
    {assign var="dateDiff" value=$date2 - $date1}
    
    {$dateDiff|date_format:'%Y-%m-%d %H:%M:%S'}