将日期与特定日期进行比较,并将日期时间与 Twig 中的字符串进行比较 [英] Compare date with a specific one and DateTime to string in Twig

查看:42
本文介绍了将日期与特定日期进行比较,并将日期时间与 Twig 中的字符串进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 当第一个日期来自 dababase 而第二个日期清晰时,我如何比较 Twig 中的两个日期 - 2012-12-31?我试过

  1. 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. :(

我有一个 DateTime 字段,但我在 Twig 中找不到 DateTime 的过滤器,当我使用 |date('Ym-d') 时,它只打印日期,而没有小时 :(

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') }}

这篇关于将日期与特定日期进行比较,并将日期时间与 Twig 中的字符串进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆