Previous Topic Next topic Print topic


REPATTERN Function

Purpose

Takes a value containing a date in one pattern and returns that value converted to a date in another pattern.

Syntax

REPATTERN (d, p, q, w)

Parameters

d is a string expression representing a date. The length of d must be at least as long as the length of the source pattern specified by q. If d is larger, any excess characters must be formed by leading blanks.

The value for d must have a computational type and should have a character type. If not, the REPATTERN function converts d to character.

p is a supported date/time pattern used as the target.

q is a supported date/time pattern used as the source.

w specifies an expression (such as 1976) that can be converted to an integer.

  • Any positive numeric value is treated as a year.
  • Negative values are treated as an offset and subtracted from the current, system-supplied year.
  • If not specified, the value of w is the value specified in the -window compile-time option.

Description

The REPATTERN function takes a value containing a date in one pattern and returns that value converted to a date in a second pattern. The returned value has the attributes CHAR(m) NONVARYING where (m) is the length of the target pattern specified by p.

Examples

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

repat: proc options(main);

    dcl str char(16)var;

    on error
    begin;
        put skip list ('Error raised. Outside century window.');
        STOP:
    end;

    str = REPATTERN('770101','YYYYMMDD','YYMMDD', 1976);
    put skip list (str);

    str = REPATTERN('280101','YYYYMMDD','YYMMDD', 1976);
    put skip list (str);

    str = REPATTERN('19770101','YYMMDD','YYYYMMDD', 1976);
    put skip list (str);

    str = REPATTERN('20280101','YYMMDD','YYYYMMDD', 1976);
    put skip list (str);

    str = REPATTERN('19700101','YYMMDD','YYYYMMDD', 1976);
    put skip list (str);

end;

This code sample prints the following:

19770101

20280101

770101

280101

Error raised. Outside century window.

Restrictions

None.

Previous Topic Next topic Print topic