13

i get date with: {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}

But how get 20 day after?

If now: 2010 05 05 12:12:12, I wish to show 2010 25 05 12:12:12

dippas
  • 58,591
  • 15
  • 114
  • 126
lolalola
  • 3,773
  • 20
  • 60
  • 96

6 Answers6

19

{$smarty.now} is a simple timestamp (number of seconds since 1970). So you can just add as many seconds to it as you need:

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

This works in Smarty3, if not in older versions then you might need to do the math with {assign} and/or {math} directives.

serg
  • 109,619
  • 77
  • 317
  • 330
8

Use the strtotime() php function and assign your variable to smarty. Something like this:

<?php
$later = strtotime('+20 day');
$smarty->assign('later', $later);
?>

Then in the template:

{ $later|date_format:'%Y-%m-%d %H:%M:%S'}
Cfreak
  • 19,191
  • 6
  • 49
  • 60
7

You can use strtotime() directly as a modifier.

{"+20 days"|strtotime|date_format:"Y/m/d"}
mohrt
  • 464
  • 5
  • 3
3

In newer versions of smarty it will strtotime any string you prepend

I.e. instead of doing {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'} you can also do {"now"|date_format:'%Y-%m-%d %H:%M:%S'}

To get the date 20 days from now, you can do:

{"+20 days"|date_format:"%Y-%m-%d"}

skrilled
  • 5,350
  • 2
  • 26
  • 48
0
{assign var="iItemOne" value=$smarty.now}
{assign var="iItemTwo" value=1296000} //60*60*24*15-> for 15 days
{assign var="iSum" value=$iItemOne+$iItemTwo}

{$iSum|date_format:'%Y-%m-%d %H:%M:%S'}
-1

Tested in smarty : Add 1 day ,2 days ......365 days in dynamic date.

$one= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 1 day"));
  $this->smarty->assign('one',$one);

$two= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 2 day"));
  $this->smarty->assign('two',$two);
...
..

$oneyear= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 365 day"));
  $this->smarty->assign('oneyear',$oneyear);
Rizier123
  • 58,877
  • 16
  • 101
  • 156