Dvir Yadae
Dvir Yadae

Reputation: 103

How to add "N" days to $smarty.now?

I have a parameter in my page called 'priceValidUntil', for this parameter I have the line:

<meta itemprop="priceValidUntil" content="{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}">

I want to add to the $smarty.now value 15 days, so I've added this:

 <meta itemprop="priceValidUntil" content="{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S' + 15 }">

The output is this:

 <meta itemprop="priceValidUntil" content="2024-04-27 23:04:05">

I want:

<meta itemprop="priceValidUntil" content="2019-05-12 23:04:05">

How can I add days instead of years?

Upvotes: 3

Views: 4534

Answers (2)

deWebLooper
deWebLooper

Reputation: 21

Use both methods to try which one fits better to you. For example in Prestashop 1.6.x is OK to use method 2, without errors.

Upvotes: 0

Emma
Emma

Reputation: 27743

Method 1

According to this link, it seems you might be able to do so, maybe by adding:

 {$smarty.now+24*60*60*15|date_format:'%Y-%m-%d %H:%M:%S'}

to your content attribute.

  • In the numbers, 24 is hours, one of 60 stands for minutes and the other 60 stands for seconds, times by 15 days, is to calculate the seconds that you wish to add to $smarty.now variable.

  • Then, your code may look like:

    <meta itemprop="priceValidUntil" content="{$smarty.now+15*24*60*60|date_format:'%Y-%m-%d %H:%M:%S'}">
    

Method 2

You might simply try this:

{"+15 days"|strtotime|date_format:'%Y-%m-%d %H:%M:%S'}

Then, your code might look like:

<meta itemprop="priceValidUntil" content="{$smarty.now+1296000|date_format:'%Y-%m-%d %H:%M:%S'}">

Upvotes: 4

Related Questions