Subtract two dates in Microsoft SQL Server

SELECT     DATEDIFF(day,'2014-06-05','2014-08-05')     AS DiffDate

Output DiffDate 61

More practice please refer below W3 school:

https://www.w3schools.com/sql/func_sqlserver_datediff.asp


Here you don't have to cast GETDATE() to date, as it is already datetime datatype. So your query will be as follows

SELECT DATEDIFF(day,CAST(LastUsedDate as date),GETDATE()) AS DifferneceDays
FROM TableName

The normal function to use is datediff():

select datediff(day, cast('2016-02-03' as date), cast('2016-03-30' as date))

You can subtract datetime values, but not dates. Alas.