Subtract days from date with SORT

4.1k views Asked by At

I want to subtract a day from the given input date using SyncSORT? The input date is in YYYYMMDD format.

Ex:

Input date: 20111031 (Format: YYYYMMDD)
Output date after minus 1 day: 20111030 (Format: YYYYMMDD). 
2

There are 2 answers

0
Prayag KL-13 On

This works with DFSORT. It does not work with SyncSORT up to 1.4.x. It may work (let us know) with SyncSORT (Mainframe Express, or MFX) 2.x and it may even work without being documented. Or not.

SORT FIELDS=COPY                                      
INREC OVERLAY=(1:1,8,Y4T,SUBDAYS,+1,TOGREG=Y4T)

It may help you.

0
Bill Woodger On

Date arithmetic with SyncSORT is significantly different to that with DFSORT (at least up to 1.4.x, who knows about later releases?)

This says, "putting the result into column one of the current record, take position one for a length of eight, in the format of a four-digityear followed by a two-digit month and a two-digit day, add use the function DATEADD to add minus one units (ie subtract) and those units are days. The result will be in the same format as the source".

SORT FIELDS=COPY                                      
INREC OVERLAY=(1:DATEADD=(1,8,DT=(4MD),-1,DAY))

Many input formats can be expressed, and there are several options to describe the units (valid depending on the format of the input). Input formats can be described with separators, and these will remain in the output.