REPATTERN

REPATTERN takes a value holding a date in one pattern and returns that value converted to a date in a second pattern.

Read syntax diagramSkip visual syntax diagramREPATTERN( d, p, q, w)
d
A string expression representing a date. The length of d must be at least as large as the length of the source pattern q. If d is larger, any excess characters must be formed by leading blanks.

d must have a computational type and should have character type. If not, it is converted to character.

p
The target pattern; must be one of the supported date/time patterns.
q
The source pattern; must be one of the supported date/time patterns.
w
Specifies an expression (such as 1950) that can be converted to an integer. If negative, it specifies an offset to be subtracted from the value of the year when the code runs. If omitted, w defaults to the value specified in the WINDOW compile-time option.

The returned value has the attributes CHAR(m) NONVARYING where m is the length of the target pattern p.

The allowed patterns are listed in Table 2. For an explanation of Lilian format, see Date/time built-in functions.

The REPATTERN built-in function will perform the specified conversion in-line when both of the following are true:
  • the source and target patterns do not use the DDD, MMM or Mmm elements
  • the source pattern has as much date information as the target, i.e. if the target has a year, month or day, then the source must have the corresponding information and there must also be at least as many digits in the source year as in the target.
So, for example,
  • YYYYMMDD to DD.MM.YY will be inlined
  • MM/DD/YYYY to YYMM will be inlined
  • MMYY to YYYYMMDD will not be inlined

The following are some examples of how to use REPATTERN to convert between 2-digit-year and 4-digit-year date patterns. But you can use this built-in function to convert a date from any supported pattern to any other supported pattern even if the patterns use the same number of digits to hold the year value.

REPATTERN('990101','YYYYMMDD','YYMMDD', 1950) returns '19990101'
REPATTERN('000101','YYYYMMDD','YYMMDD', 1950) returns '20000101'
REPATTERN('19990101','YYMMDD','YYYYMMDD', 1950) returns '990101'
REPATTERN('20000101','YYMMDD','YYYYMMDD', 1950) returns '000101'
REPATTERN('19490101','YYMMDD','YYYYMMDD', 1950) raises ERROR