Search code examples
phpdatesmarty

Compare two dates in smarty


I have two dates in respective format (02-Dec-14 and 17-Dec-14 ) and i want to compare these two dates in smarty.

How can i compare these two dates ? please help.

Thanks In Advance


Solution

  • If you have those dates assigned to Smarty for example this way:

    $smarty->assign('date2','02-Dec-14');
    $smarty->assign('date1','17-Dec-14');
    

    you can use strtotime function directly in Smarty, for example:

    {if $date1|strtotime < $date2|strtotime}
        {$date1} is earlier than {$date2}
    {elseif $date1|strtotime == $date2|strtotime}
        Both dates are the same
    {else}
        {$date2} is earlier than {$date1}
    {/if}