$DateDif: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
m (Added left parentheses)
Line 2: Line 2:
<b>Syntax</b>
<b>Syntax</b>
<p>The format of the $DATEDIF function is:</p>
<p>The format of the $DATEDIF function is:</p>
<p class="code">$DATEDIF date-1-format,date-1,date-2-format,date-2,
<p class="code">$DATEDIF(date-1-format,date-1,date-2-format,date-2,defcent,centsplt)</p>
 
          defcent,centsplt)  
</p>
<p>where:</p>
<p>where:</p>
<ul>
<ul>

Revision as of 17:38, 3 April 2014

The $DATEDIF function returns the difference in days between the two dates.

Syntax

The format of the $DATEDIF function is:

$DATEDIF(date-1-format,date-1,date-2-format,date-2,defcent,centsplt)

where:

  • Date-1-format specifies the format of the first 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.

  • Date-1 specifies the first date in the format specified by the date-1-format argument. The date can be as many as 36 characters in length.
  • Date-2-format specifies the format of the second date. The format requirements are the same as those for the date-1-format argument. This argument can be omitted but the comma after it is required. If this argument is omitted, $DATEDIF assumes that date-2 is in the same format as date-1.
  • Date-2 specifies the second date. The date must be either in the format specified in the date-2-format argument, or in the format specified in date-1-format if date-2-format is not specified. The date can be as many as 36 characters in length.
  • The 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.
  • The centsplt argument (optional) specifies the CENTSPLIT 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.

Dates in differing centuries

In the following procedure Date_Difference, the $DATEDIF function calculates the difference between dates twice. Before the first PRINT command, the CUSTOM parameter is set to 1, so the century defaults to the current century. Before the second PRINT command, the DEFCENT parameter is set to 20.

PROCEDURE DATE_DIFFERENCE RESET CUSTOM =(1 BEGIN PRINT $DATEDIF('CYYDDD','96333','YY MM DD','97 06 22',- %DEFCENT,%CENTSPLT) %DEFCENT = 20 PRINT $DATEDIF('CYYDDD','096333','YY MM DD','97 06 22',- %DEFCENT,%CENTSPLT) 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

  • The separators in each format must match the separators in the corresponding date. For example:
  • $DATEDIF('MON DD, YYYY','JAN 08, 1990', - 'YY:DDD', '88:210')

  • When necessary, pad the month or date in the date argument with leading zeros to match the length of corresponding format argument. For example:
  • $DATEDIF('YY DDD','90 034',,'90 007')

How $DATEDIF works

  • If date1 is the same as date2, 0 is returned.
  • If date1 is earlier than date2, a negative integer is returned.
  • If date1 is later than date2, a positive integer is returned.
  • If an error occurs, 999999999 is returned.

Example

PRINT $DATEDIF('MMDDYY','010790',,'040891')

prints this value:

-456