Compare date with a specific one and DateTime to string in Twig(将日期与特定日期和 DateTime 与 Twig 中的字符串进行比较)
问题描述
How can I compare two dates in Twig when the first one comes from the dababase and the second is clear - 2012-12-31? I tried with
{% if dom.dueDate|date('Y-m-d') > 2012-12-31 %}
but I don't get the result I want. :(
I have a DateTime field but I couldn't find a filter for DateTime in Twig and when I use
|date('Y-m-d')
it prints only the date without the hour :(
I would be really happy and grateful if someone helps me to solve the problems!
Try timestamps for comparison :
{% if dom.dueDate|date('U') > '2012-12-31'|date('U') %}
and this to add hours, minutes and seconds
{{ dom.dueDate|date('Y-m-d H:i:s') }}
这篇关于将日期与特定日期和 DateTime 与 Twig 中的字符串进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将日期与特定日期和 DateTime 与 Twig 中的字符串进行比较


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Laravel 仓库 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01