本文介绍了得到两个日期之间的时间差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较两个日期,以得到TWIG中的时间(天,小时,分钟和秒)差异

I would like compare the two dates to get a time (Days, Hours, minutes and seconds) difference in TWIG

{% set todayDate = ( "now"| date("Y-m-d H:i:s") ) %}  //2013-04-17 08:45:28
{% set endDate =  (enddate|date('Y-m-d H:i:s')) %}    //2013-04-18 23:59:59

如何获得小时差异?

推荐答案

最后我得到它..
比较两个日期控制器中的时间(天,小时和分钟)

Finally i got it.. compare the two dates to get a time (Days, Hours and minutes) in controller :

(doctrine查询)

(doctrine query)

TIMESTAMPDIFF(DAY,CURRENT_TIMESTAMP(), a.enddate) AS endday,
(TIMESTAMPDIFF(HOUR,CURRENT_TIMESTAMP(), a.enddate) - TIMESTAMPDIFF(DAY,CURRENT_TIMESTAMP(),a.enddate)*24) AS endhour,
(TIMESTAMPDIFF(MINUTE,CURRENT_TIMESTAMP(), a.enddate) - TIMESTAMPDIFF(HOUR,CURRENT_TIMESTAMP(), a.enddate)*60) AS endmin,

为TIMESTAMPDIFF创建了一个函数

Created a function for TIMESTAMPDIFFhttps://github.com/beberlei/DoctrineExtensions/blob/master/lib/DoctrineExtensions/Query/Mysql/TimestampDiff.php

并包含一个片段

app-> config-> config.yml
教义:
dbal:
........

app->config->config.ymldoctrine: dbal: ........

orm:
    entity_managers:
        default:
            auto_mapping: true
            dql:
                datetime_functions:
                    timestampdiff: Acme\BUNDLE\FOLDER\TimestampDiff

感谢所有..

这篇关于得到两个日期之间的时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 23:29