I have a basic query:
SELECT dtCreated
, bActive
, dtLastPaymentAttempt
, dtLastUpdated
, dtLastVisit
FROM Customers
WHERE (bActive = 'true')
AND (dtLastUpdated > CONVERT(DATETIME, '2012-01-0100:00:00', 102))
I want to add another column to the output... lets call it "Difference" to find out the number of days between 'dtcreated' and 'dtlastupdated' So for example if record 1 has a dtcreated of 1/1/11 and dtlastupdated is 1/1/12 the "Difference" column would be "365".
Can this be accomplished in a query?
To find the number of days between two dates, you use:
do it
If you are using MySQL there is the DATEDIFF function which calculate the days between two dates:
The DATEDIFF function is use to calculate the number of days between the required date
Example if you are diff current date from given date in string format
Here, STR_TO_DATE () : Take a string and returns a date specified by a format mask;
For your example :
Tested on mysql server 5.7.17
As @Forte L. mentioned you can do the following as well;