ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Date Math Problem

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Math Problem

    We have dates stored as 8,0 like 20220421
    In my query I can subtract a date from current_date in the select statement and see the # of days difference.
    But if I put that same statement in my WHERE clause I get an error.

    This works fine. The last column shows a number

    Code:
    SELECT CYC.* , (Days(Current_Date ) - Days(Digits(CYCLLAST) concat '000000'))
    FROM CYCRCP01EP CYC
    where WHSE = 'EP' and COUNT30 = 0
    But this gives an error

    Code:
    update CYCRCP01EP
    set count30 = 1
    where WHSE = 'EP' and COUNT30 = 0 AND (Days(Current_Date ) - Days(Digits(CYCLLAST) concat '000000'))  <= 30
    Code:
    [COLOR=#C71414]SQL State: 22007
    Vendor Code: -181
    Message: [SQL0181] Value in date, time, or timestamp string not valid. Cause . . . . . : The string representation of a date, time or timestamp value is not in the
    acceptable range. *N is either the character string constant that is not valid or the column or host variable that contained the string. If the name is *N, then the value was found in an expression specified in the statement. If the value was found in a host variable, then the host variable number is 0. The proper ranges for
    date, time, or timestamp values are as follows: --
    The range for years is from 0001 to 9999. For date formats *MDY, *YMD, *DMY, and *JUL, the year must be in the range 1940 to 2039. -- The range for months is from 1 to 12. -- The range for days is from 1 - 30 for April, June, September, and November, from 1 - 28 for
    February and from 1 to 31 for all other months. In a leap year, the range for February can be from 1 to 29. --
    The range for days in a Julian date is from 001 to 366 for a leap year or 001 to 365 days for all other years. --
    The range for hours is from 0 to 24. If the hour is 24, then the other parts of the time values must be zeros.
    If the time format is USA, then the hour cannot be greater than 12. -- The range for minutes is from 0 to 59. --
    The range for seconds is from 0 to 59. -- The range for fractional seconds is from 0 to 999999999999. Recovery . . . : Ensure that the date, time, or timestamp value conforms to the ranges for the data type it represents. Try the request again.[/COLOR]
Working...
X