Contract expire in next 30 days

Contract expire in next 30 days



MSSQL


SELECT mcdt.CONTRACTNAME "Contract Name",
       r.resourcename "Asset",
       longtodate(mcdt.todate) "Date" FROM MaintenanceContract mcdt
LEFT JOIN contractdetails cd ON cd.contractid = mcdt.contractid
LEFT JOIN resources r ON r.resourceid = cd.resourceid
WHERE ((mcdt.todate/1000)-DATEDIFF(s, '19700101', GETDATE()))/60/60/24 >=1
  AND ((mcdt.todate/1000)-DATEDIFF(s, '19700101', GETDATE()))/60/60/24 <=30
ORDER BY 1


PGSQL

SELECT mcdt.CONTRACTNAME "Contract Name",
       r.resourcename "Asset",
       longtodate(mcdt.todate) "Date"
FROM MaintenanceContract mcdt
LEFT JOIN contractdetails cd ON cd.contractid = mcdt.contractid
LEFT JOIN resources r ON r.resourceid = cd.resourceid
WHERE extract(epoch
              FROM(to_timestamp(mcdt.todate/1000)::TIMESTAMP - now()::TIMESTAMP))/3600/24 >=1
  AND extract(epoch
              FROM(to_timestamp(mcdt.todate/1000)::TIMESTAMP - now()::TIMESTAMP))/3600/24 <=30
ORDER BY 1

                  New to ADSelfService Plus?