'SQL finding the max of the difference of two dates

I have two dates (run date) and (date due). I need to find the largest delinquent date which would be the largest (max) number of days between the run date and the due date.

Logically I would want this to be max ( datedif ( day, run date, date due)), however, this code does not seem to run in SQL.

Please help

sql


Solution 1:[1]

You may be looking for this script

SELECT TOP(1) *,DATEDIFF(day,[run date],[date due])) AS DDiff
FROM TableName
ORDER BY DDiff DESC;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nicholas K