ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Julian format date in SQLRPGLE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Julian format date in SQLRPGLE

    SET LSTCOUNT = DATE(DIGITS( DECIMAL(:ConvertDate +1900000,7,0)))
    ConvertDate is of Julian format, i am trying to convert to a regular date in file, but it doesnt accept it: "column or variable LSTCOUNT not compatible. "
    I changed the field LSTCOUNT from L type to zoned 8,0 - same result
    What type should it be or what other options?
    Thanks.

  • #2
    1. If you have the data type L it is already a date. No need to convert anything. You can only format the date, i.e. convert into a character representation of a date. For converting a date or a timestamp into a character representation, in almost any format use the VARCHAR_FORMAT scalar function.
    https://www.ibm.com/docs/en/i/7.4?topic=functions-varchar-format
    2.
    The format of a julian date is 4 digit year and 3 digit (running) day in the year.
    Here are several ways to covert a character or numeric date in the Julian Format into a real date

    Code:
    With x (DateNum, DateChar) as (Values(Cast(2022123 as Dec(7, 0)), Cast('2022125' as Char(7))))
    Select x.*, Date(Digits(DateNum)),
    Date(Timestamp_Format(Digits(DateNum), 'YYYYDDD')),
    Date(DateChar),
    Date(Timestamp_Format(DateChar, 'YYYYDDD'))
    from x;
    Birgitta

    Comment

    Working...
    X