PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] How to add "N" days to $smarty.now?

 June 28, 2022     date, php, prestashop, prestashop-1.6, smarty     No comments   

Issue

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?


Solution

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'}">


Answered By - Emma
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing