第二个 IF 语句被忽略

发布于 2025-01-14 11:07:08 字数 771 浏览 3 评论 0原文

为什么变量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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携余温的黄昏 2025-01-21 11:07:08

如果日期在变量和 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') %}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文