Social Icons

twitter email

Tuesday, August 5, 2014

Convert between different types of dates using DFSORT


DFSORT's TOJUL and TOGREG functions make it easy to convert between various types of Julian, Gregorian,4-digit year, 2-digit year, CH, ZD, and PD dates.

1. The following DFSORT job converts a 'yyyymmdd' date to a 'yyyyddd' date:
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
20090520
20100106
20100921
20081217
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC BUILD=(1,8,Y4T,TOJUL=Y4T)
/*
SORTOUT would have these records:
2009140
2010006
2010264
2008352
2. The following DFSORT job converts a 'yymmdd' date to a 'yyyy-ddd' date:
//S2 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
ABC 090520
DEF 100106
GHI 100921
JKL 081217
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION Y2PAST=1990
SORT FIELDS=(5,6,Y2T,A)
OUTREC OVERLAY=(5:5,6,Y2T,TOJUL=Y4T(-))
/*
SORTOUT would have these sorted records:
JKL 2008-352
ABC 2009-140
DEF 2010-006
GHI 2010-264
3. The following DFSORT job converts a P'dddyyyy' date starting in position 21 to a 'mm-dd-yyyy' date starting in position 51:
//S3 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file
//SORTOUT DD DSN=... output file
//SYSIN DD *
OPTION COPY
OUTFIL OVERLAY=(51:21,4,Y4X,TOGREG=Y4W(-))
/*
Here's an example of the input and converted fields:
21            51
P'2122008' -> 07-30-2008
P'0722010' -> 03-13-2010
4. The following DFSORT job converts a 'yyyy-mm-dd' date to a P'mmddyy' date.
//S4 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
2009-05-20
2010-01-06
2010-09-21
2008-12-17
//SORTOUT DD DSN=... output file
//SYSIN DD *
SORT FIELDS=(1,10,CH,A)
OUTREC IFTHEN=(WHEN=INIT,BUILD=(1,10,UFF,TO=ZD,LENGTH=8)),
IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4T,TOGREG=Y2Y))
/*
Here's what the sorted and converted fields would look like:
P'121708'
P'052009'
P'010610'
P'092110'
5. The following DFSORT job converts a 'mm/dd/yyyy' date to a 'yyyyddd' date:
//S5 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
04/08/2006ABC
11/15/2008DEF
09/30/2010GHI
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,
BUILD=(1,10,UFF,TO=ZD,LENGTH=8,9:11,3)),
IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4W,TOJUL=Y4T,9,3))
/*
SORTOUT would have these records:
2006098ABC
2008320DEF
2010273GHI

1 comment:

  1. Hi,

    Could you please share the details for comparing the date format DDMMYYYY to current date.

    ReplyDelete

 
Blogger Templates