|
|
![]() |
|
|
|
|
||
|
OPNQRYF Date Arithmetic Hey, Ted: I need to select records for the period beginning 210 days ago and ending 30 days ago using Open Query File (OPNQRYF). The date field is eight digits packed, in YYYYMMDD format.
I thought this was going to be easy, but I am a little tired and stumped. So how do I do this? -- David You'll have to convert that numeric date to a date data type in order to use OPNQRYF's date duration functions. Here's an example that illustrates the conversion:
DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(512)
DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(512)
CHGVAR VAR(&QRYSLT) +
VALUE('DtDate *ge (%curdate - %durday(210)) *and +
DtDate *le (%curdate - %durday(30))')
OPNQRYF FILE((GLJNLY)) QRYSLT(&QRYSLT) +
MAPFLD((DIGDATE '%DIGITS(jedate)' *CHAR 8) +
(EDDATE '%sst(digdate 5 2) *cat "/" +
*cat %sst(digdate 7 2) *cat "/" +
*cat %sst(digdate 3 2)' *CHAR 8) +
(DTDATE '%date(eddate)' *DATE))
CPYFRMQRYF FROMOPNID(GLJNLY) TOFILE(QTEMP/X) +
MBROPT(*REPLACE) CRTFILE(*YES)
CLOF OPNID(GLJNLY)
RUNQRY QRYFILE((QTEMP/X))
The trick to this is in the three mapped fields. DIGDATE uses the %digits function to convert the numeric field to an eight-byte character field. EDDATE uses substringing and concatenation to reformat DIGDATE into the system format, which, on the Netshare/400 machine on which I created this example, is MM/DD/YY. The DTDATE field changes EDDATE to the date data type. The QRYSLT parameter selects records based on DTDATE, not the original field JEDATE. -- Ted
|
Editors
Contact the Editors |
|
Last Updated: 9/25/02 Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |