How to find the number of days between two dates

后端 未结 9 581
独厮守ぢ
独厮守ぢ 2021-01-04 06:43

I have a basic query:

SELECT dtCreated
    , bActive
    , dtLastPaymentAttempt
    , dtLastUpdated
    , dtLastVisit
FROM Customers
WHERE (bActive = \'true\         


        
9条回答
  •  迷失自我
    2021-01-04 07:26

    I would use the DATE_DIFF function to provide this value as below:

    SELECT dtCreated
        , bActive
        , dtLastPaymentAttempt
        , dtLastUpdated
        , dtLastVisit
        , DATEDIFF(d, dtLastUpdated, dtCreated) AS Difference
    FROM Customers
    WHERE (bActive = 'true') 
        AND (dtLastUpdated > CONVERT(DATETIME, '2012-01-0100:00:00', 102))
    

    EDIT: IF using MySQL you omit the 'd' leaving you with

    DATEDIFF(dtLastUpdated, dtCreated) AS Difference
    

提交回复
热议问题