Suppose you had an input file with gregorian input dates in ccyymmdd
form like this:
20070305
20071213
20080219
20080901
20091122
20090115
20100915
20100630
You can use these statements:
OUTREC BUILD=(1,8,Y4T,ADDDAYS,+50,TOGREG=Y4T(/),2X,
1,8,Y4T,SUBMONS,+7,TOGREG=Y4T(/),2X,
1,8,Y4T,ADDYEARS,+2,TOGREG=Y4T(/))
to display the original date and perform arithmetic on these dates
as follows:
- Add 50 days
- Subtract 7 months
- Add 2 years
The results produced for this OUTREC statement are:
2007/04/24 2006/08/05 2009/03/05
2008/02/01 2007/05/13 2009/12/13
2008/04/09 2007/07/19 2010/02/19
2008/10/21 2008/02/01 2010/09/01
2010/01/11 2009/04/22 2011/11/22
2009/03/06 2008/06/15 2011/01/15
2010/11/04 2010/02/15 2012/09/15
2010/08/19 2009/11/30 2012/06/30
You can perform various types of arithmetic on date fields in either
julian or gregorian form, with 2-digit (Y2x) or 4-digit (Y4x) years,
in CH, ZD or PD format. You can convert the result to the same form
of date or another form, with or without separators.
You can use the following date arithmetic functions:
- ADDDAYS, ADDMONS and ADDYEARS can be used to add days, months
or years to a date field.
- SUBDAYS, SUBMONS and SUBYEARS can be used to subtract days, months
or years from a date field.
- DATEDIFF can be used to calculate the number of days between two
date fields.
- NEXTDday can be used to calculate the next specified day of the
week for a date field (where day can be SUN, MON, TUE, WED, THU,
FRI or SAT).
- PREVDday can be used to calculate the previous specified day of
the week for a date field (where day can be SUN, MON, TUE, WED, THU,
FRI or SAT).
- LASTDAYW, LASTDAYM, LASTDAYQ and LASTDAYY can be used to calculate
the last day of the week, month, quarter or year for a date field.
For complete details on using date field arithmetic functions,
see z/OS DFSORT Application Programming Guide.