第二个 IF 语句被忽略
为什么变量currentday不输出:2 Condition? 不知何故,它没有进入第二个 IF 语句。
{% set currentday = '10.04.2022'|date('d.m.Y') %}
<h1>Today: {{ currentday }}</h1>
{% if currentday >= '01.01.2022' and currentday <= '31.03.2022' %}
<h1>1 Condition </h1>
{% elseif currentday >= '01.04.2022' and currentday <= '30.06.2022' %}
<h1>2 Condition </h1>
{% elseif currentday >= '01.07.2022' and currentday <= '30.09.2022' %}
<h1>3 Condition </h1>
{% elseif currentday >= '01.10.2022' and currentday <= '31.12.2022' %}
<h1>4 Condition </h1>
{% endif %}
Why is the variable currentday not outputing: 2 Condition?
Somehow it is not entering the second IF statement.
{% set currentday = '10.04.2022'|date('d.m.Y') %}
<h1>Today: {{ currentday }}</h1>
{% if currentday >= '01.01.2022' and currentday <= '31.03.2022' %}
<h1>1 Condition </h1>
{% elseif currentday >= '01.04.2022' and currentday <= '30.06.2022' %}
<h1>2 Condition </h1>
{% elseif currentday >= '01.07.2022' and currentday <= '30.09.2022' %}
<h1>3 Condition </h1>
{% elseif currentday >= '01.10.2022' and currentday <= '31.12.2022' %}
<h1>4 Condition </h1>
{% endif %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果日期在变量和 if/else 中以这种方式格式化,那么它就像一个魅力:
{% set currentday = '2022-08-10'|date('Ymd') %}
If the date is formatted in this way in the variable and if/else then it works like a charm:
{% set currentday = '2022-08-10'|date('Y-m-d') %}