Exclude weekends in $smarty.now dates

50 Views Asked by At

I want add X days depending to date of week. My variable is working just now with the code:

{$order.details.order_date|replace:'/':'-'|cat:' +8 days'|date_format:'%A, %e de %B del %Y'}

I want if the days are Monday, Tuesday, Wednesday and Thursday incresase 8 days and with the previous code it works, but for friday and saturday i want add 10 days, and for sunday 9 days. It is not working, it seem to read just the last code {if $Delivery_day > 0 && $Delivery_day < 5}

{assign var="Delivery_day" value=$smarty.now|date_format:"%u"}
    {if $Delivery_day == 7} *// sunday
        {$order.details.order_date|replace:'/':'-'|cat:' +9 days'|date_format:'%A, %e de %B del %Y'}
    {/if}
    {if $Delivery_day == 5} *// friday
        {$order.details.order_date|replace:'/':'-'|cat:' +10 days'|date_format:'%A, %e de %B del %Y'}
    {/if}
    {if $Delivery_day == 6} *// saturday
        {$order.details.order_date|replace:'/':'-'|cat:' +10 days'|date_format:'%A, %e de %B del %Y'}
    {/if}
    {if $Delivery_day > 0 && $Delivery_day < 5} *//monday,tuesday,wednesday,thursday
        {$order.details.order_date|replace:'/':'-'|cat:' +8 days'|date_format:'%A, %e de %B del %Y'}
    {/if}

Note: Your code should be work in .tpl file, smarty and php8

0

There are 0 best solutions below