Search code examples
sqlibm-midrange

date math with curdate


I need to perform a select where my lpdt7 is within 7 days of today. Code below returns: "Value in date, time, or timestamp string not valid."

SELECT lnmast.sname,
       lnmast.status,
       ddmast.acctno,
       ddmast.status,
       date(digits(lpdt7)) AS closed
FROM mydat.lnmast lnmast
LEFT OUTER JOIN mydat.ddmast ddmast ON lnmast.cifno = ddmast.cifno
AND lnmast.altadd = ddmast.altadd
WHERE lnmast.status = 2
  AND date(digits(lpdt7)) >= curdate() -7 days

Solution

  • My error guys. I had to trap for null values in the date field first.

    WHERE lnmast.status = 2 and lpdt7 > 1 and date(digits(lpdt7)) >= curdate() - 7 days