$DateCnv

From m204wiki
Revision as of 13:18, 20 April 2013 by Alex (talk | contribs) (Automatically generated page update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The $DATECNV function converts an input date from its current format to a format you specify and, also, determines whether the input date is valid. If a format error occurs or the input date is not valid, the function returns all asterisks (*). $DATECNV supports both a 2- and a 4-digit year format; the year prefix can come from one of four places.

Syntax

The format of the $DATECNV function is:

$DATECNV(input format,output format,input date, defcent, centsplt)

where:

  • input format specifies the format of the input date. The format can be a combination of these elements:
  • DD Gregorian numeric day
    DDD Julian numeric date
    MM Numeric month
    MON Abbreviated month name
    MONTH Full month name
    YY Last two digits of numeric year (assumes that the year prefix is 19)
    YYYY Full numeric year
    CYY The century, plus the year. Century (C) is a single digit, where 0 represents 1900, 1 represents 2000, and so on.

    Valid formats are:

A format that has a month, day, and year element

A Julian date format that has a year element and a day element in the format DDD

Any EBCDIC characters except single quotes are allowed within the input format and appear unchanged in the output date. The input format can be as many as 32 characters in length.

When you use a 2-digit year, for example, YY is 98) in the input format and a 4-digit year (YYYY) in the output format, Model 204 assumes that the century is 19-, for example, 1998.

  • output format specifies the format of the output date. The format requirements are the same as those for the input format argument. Using a 2-digit year (YY) in the output format leaves you with no way to distinguish between centuries. For example:
  • $DATECNV('MON DD, YYYY', 'YY DDD', 'JAN 10, 2005')

    produces the following output:

    05 010

    However, the output is exactly the same if the input date is January 10, 1905 or January 10, 2105.

  • input date specifies the input date in the format indicated by the input format argument. The input date can be as many as 36 characters in length.
  • defcent argument (optional) specifies the DEFCENT value to use; it overrides all other DEFCENT and CENTSPLT parameter values. This argument cannot be specified with the centsplt argument, unless one of the values is NULL.
  • centsplt argument (optional) specifies the CENTSPLT value to use; it overrides all other DEFCENT and CENTSPLT parameter values. This argument cannot be specified with the defcent argument, unless one of the values is NULL.

The following example illustrates the use of the $DATECNV converting dates in various centuries.

PROCEDURE CENTSPLT BEGIN %INPUT_FORMAT = 'YYDDD' %OUTPUT_FORMAT = 'YYYY MM DD' %INPUT_VALUE = '9633' %CENTSPLT = 97 %DEFCENT = ' ' CALL PIT %CENTSPLT = ' ' %DEFCENT = 19 CALL PIT %INPUT_FORMAT = 'YYYYDDD' %INPUT_VALUE = '2006333' CALL PIT PIT: SUBROUTINE PRINT %INPUT_FORMAT ' ' %OUTPUT_FORMAT ' ' %INPUT_VALUE - ' ' %DEFCENT ' ' %CENTSPLT PRINT $DATECNV(%INPUT_FORMAT, %OUTPUT_FORMAT,%INPUT_VALUE, - %DEFCENT, %CENTSPLT) RETURN END SUBROUTINE END END PROCEDURE

For an explanation of the DEFCENT and CENTSPLT parameters processing see Rocket Model 204 Parameter and Command Reference Manual in the chapter on parameters.

Separators and leading zeros

Use separators and leading zeros as specified here:

  • Separators in the input format argument must match the separators in the input date argument. For example:
  • $DATECNV('MONTH - DD - YYYY','MON DD, YYYY', - 'JANUARY - 05 - 1990')

  • When necessary, you must pad the month or date in the input date argument with leading zeros to match the length of input format. For example:
  • $DATECNV('YY DDD','MON DD, YYYY','90 023')

Example

PRINT $DATECNV('DDMMYY','MON DD, YYYY','010790')

prints this value:

JUL 01, 1990