Date to Numeric

DateToDec - Convert Date to Decimal

The DateToDec procedure returns the date as an 8-digit zoned decimal value. The returned decimal date format is specified on the second parameter. When returning a 6-digit date, the target may be 6 or more digits.

 result-date  DateToDec(
  InDate              D     Const DATFMT(*ISO)
  szFmt             10A     Const VARYING Options(*NOPASS)
)

See also: DateToChar DecToDate

Parameters

InDate 
[input DATE(*ISO) const]  The date (in any date format) that is to be converted to numeric.

szFmt [optional]
[input const]  An optional date formatting code that indicates the format into which the date will be converted. An optional separator character may be specified in the final position of the szFMT parameter. if specified, this value overrides the default separator for the indicated date format code. If a value of zero (e.g. *YMD0) is specified for the separator, then no separator is inserted into the resulting value. However, since the return value is numeric, the separator does not impact the return value.
 

szFmt Options

The szFmt parameter may contain any standard IBM RPG IV date formatting code. In other words, if the formatting code is valid on the DATFMT keyword, it may be specified here. In addition, custom date formatting codes may be specified. The table that follows lists the formatting codes that are available.

Date Format Codes Resulting Date Format
*ISO YYYYMMDD
*USA MMDDYYYY
*EUR MMDDYYYY
*MDY MMDDYY
*YMD YYMMDD
*DMY DDMMYY
*YYMD YYYYMMDD
*DMYY DDMMYYYY
*MDYY MMDDYYY
*JDE CYYDDD   /* JD Edwards Julian date format */

If the leading asterisk is not specified for the date format code, then the date is converted into the exact format specified. For example, if  'YYYYMM' is specified for the date format, then only the 4-digit year and 2-digit month are returned.

In addition to any of these formatting codes, you may specify any combination of MM, DD, YY or YYYY to build your own return format.

Return Value

The return value is the date as a zoned decimal value in the format specified by the szFMT parameter.

Examples

The final four DateToDec() calls return the date for "next" Saturday and "this" Saturday respectively. These are identified in the examples as Group 2 and Group 3.

      /INCLUDE XTOOLS/QCPYSRC,dates
     D dtNov           S               D   INZ(*SYS)
     D chgdte          S              8S 0  
     D JDEDate         S              6S 0  
 
     C                   eval      chgdte = DateToDec(dtNOV:'*ISO')
     C                   eval      jdeDate = DateToDec(dtNOV:'*JDE')

In this example, the date of the system running this program is retrieved and stored in the DTNOV field. That date is converted to ISO format (i.e., YYYYMMDD) and copied to the CHGDTE field as numeric.

The second call to DateToDec converts an ISO formatted date containing today's date to the format used by J.D. Edwards software, often referred to as "J.D.Edwards Julian".  JD Edwards dates are formatted as numeric fields, 6-digits in length in the following format:

CYYDDD

Where C = 0 to 9; YY = 2-digit year; DDD = Day of the year.  To calculate the full 4-digit year, add 19 to the C value and concatenate it with the YY value.