Smartyでの日付処理

現在 2020/01/21

{$smarty.now|date_format:'%Y/%m/%d'}

明日 2020/01/22

60秒、60分、24時間で計算。

{assign var="tomorrow" value=$smarty.now+24*60*60}
{$tomorrow|date_format:'%Y/%m/%d'}

昨日 2020/01/20

60秒、60分、24時間で計算。

{assign var="yesterday" value=$smarty.now-24*60*60}
{$yesterday|date_format:'%Y/%m/%d'}

1週間後 2020/01/28

60秒、60分、24時間、7日で計算。

{assign var="week" value=$smarty.now+24*60*60*7}
{$week|date_format:'%Y/%m/%d'}

30秒後 2020-01-21 20:33:59

30秒で計算。

{assign var="second" value=$smarty.now+30}
{$second|date_format:'%Y/%m/%d %H:%M:%S'}

30分後 2020-01-21 21:03:29

60秒、30分で計算。

{assign var="minute" value=$smarty.now+60*30}
{$minute|date_format:'%Y/%m/%d %H:%M:%S'}

24時間後 2020-01-22 20:33:29

60秒、60分、24時間で計算。

{assign var="hour" value=$smarty.now+24*60*60}
{$hour|date_format:'%Y/%m/%d %H:%M:%S'}

日付比較

日付を比較する際は、strtotimeをつけることを忘れずに。

{if ($smarty.now) < strtotime($data.created_at)}
{/if}

Category