获取两个日期之间的时差时差、两个、日期

2023-09-06 23:59:44 作者:不再让梦枯萎!

我想比较两个日期以获取 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 :

(教义查询)

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 创建了一个函数https://github.com/beberlei/DoctrineExtensions/blob/master/lib/DoctrineExtensions/Query/Mysql/TimestampDiff.php

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

并包含一个片段

app->config->config.yml教义:分贝:........

app->config->config.yml doctrine: dbal: ........

orm:
    entity_managers:
        default:
            auto_mapping: true
            dql:
                datetime_functions:
                    timestampdiff: AcmeBUNDLEFOLDERTimestampDiff

谢谢大家..