在 smarty 中创建自定义日期,使用变量中的年份以及我选择的月份和日期?

问题描述 投票:0回答:1

我对此是全新的,所以对我宽容一些。我试图从旅行开始日期中提取日期,将其用于自定义日期,这样每年我在 IF 语句中使用的日期就不必更新。

{$trip->start|date_format:'%Y'}

将告诉我旅行发生的年份。我只希望在同年 4 月 15 日之前发送的电子邮件中包含某些信息。

{if $smarty.now <= strtotime(INSERT DATE HERE 0415)} 

这就是我需要帮助的地方。我如何让它从旅行中提取年份,然后用它创建当年的 4 月 15 日,然后使用 strtotime 进行转换,以便我可以用它来限制发送的内容?

我试过这个:

{assign var="tripyear" value="$trip->start|date_format:'%Y'"}
{if strtotime($trip->start) >= strtotime("$tripyear"0415)}
{if $smarty.now <= strtotime("$tripyear"0415)}

但我不知道自己在做什么。

smarty
1个回答
0
投票

下面的代码将旅行年份分配给“tripyear”。就像你说的,但缺少一些括号:

{assign var="tripyear" value="{$trip->start|date_format:'%Y'}"}

如果您输入此内容,您将显示今天的日期:

{$smarty.now|date_format}

如果您输入此内容,它将显示

$tripyear
年 4 月 15 日的日期:

{strtotime("{$tripyear}-04-15")|date_format}

通过输入下面的代码,如果今天 (

$smarty.now
) 早于或与
$tripyear
年 4 月 15 日同一天,您只会显示文本“hello”。

{if $smarty.now <= strtotime("{$tripyear}-04-15")}
    hello
{/if}
© www.soinside.com 2019 - 2024. All rights reserved.