Search code examples
datetimeibm-midrangedatetime-formatrpgle

Convert string of length 8 to *EUR date for comparing


I want to convert a string of length 8 to a date type for comparing it. The string is formatted as DDMMYYYY (*EUR).

It has no periods for seperating the days from months and months from years. If I input a value like '01012018' to the %date BIF the compiler tells me that the expression is too short for the format *EUR:

 D dateEUR         s               d   datfmt(*EUR)
 C                   eval      dateEUR = %date('01012018':*EUR)

My previous way to compare to two dates was to take both of them, store them in datastructues, reorder the date with subfields and take the resulting, reordered date from a overlaying subfield.

Has anyone a idea of how to convert the 8A string to a DATE type in RPGLE?


Solution

  • The format you specify will depend on whether or not you store the date separators. If your date is in a 10-byte character field as DD-MM-YYYY (with the dashes), this is again EUR format:

          %date(alpha_date : *eur)
    

    If you don'tt need standard separators with your date (DDMMYYYY in an 8-byte character field) simply append the number zero (0) to the end of the format name:

          %date(alpha_date : *eur0)