Ahm*_*sam 10 symfony twig octobercms
我想检查今天的日期是否在数据库的两个日期之间.这是我的代码.
{% if today < room.price_start_date and today > room.price_end_date %}
<a href="{{'/'|app}}/book/{{room.id}}"><button type="button" class="btn btn-default btn-xs">Book this room</button></a>
{% else %}
<a href="{{'/'|app}}/contact"><button type="button" class="btn btn-default btn-xs">Book this room</button></a>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
该today变量会从这段代码的价值:
$todayDate = date('Y-m-d');
$this['today'] = date('Y-m-d', strtotime($todayDate));
Run Code Online (Sandbox Code Playgroud)
在price_start_date和price_end_date我从数据库中获取他们和他们的列的类型Date
任何想法如何检查是否today是之间room.price_start_date和room.price_end_date在嫩枝?
Far*_*ide 14
根据TWIG手册,您可以使用date功能.如果没有传递参数,则该函数返回当前日期.
所以你的代码可能在TWIG中看起来像这样:
{% if date(room.price_start_date) < date() and date(room.price_end_date) > date() %}
{# condition met #}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8619 次 |
| 最近记录: |