|
View previous topic :: View next topic
|
| Author |
Message |
expat
Global Moderator

Joined: 14 Mar 2007 Posts: 8798 Location: Welsh Wales
|
|
|
|
Trying to find the difference between two dates in European format.
I've had a google and a search of the forum but can't seem to find the correct format to use for the datediff functionality.
Any clues, pointers appreciated.
Input
| Code: |
22/01/2013 24/03/2013
14/01/2011 24/03/2013
30/01/2013 31/03/2013
17/02/2013 31/03/2013 |
Output - Where nnnn is the days difference between the two dates
| Code: |
22/01/2013 24/03/2013 nnnn
14/01/2011 24/03/2013 nnnn
30/01/2013 31/03/2013 nnnn
17/02/2013 31/03/2013 nnnn |
|
|
| Back to top |
|
 |
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1217 Location: Dublin, Ireland
|
|
|
|
How about reformatting the date, calculating the difference and then losing the reformatted date? Along the lines:
| Code: |
//SORT EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD *
22/01/2013 24/03/2013
14/01/2011 24/03/2013
30/01/2013 31/03/2013
17/02/2013 31/03/2013
//SORTOUT DD SYSOUT=*
//SYSIN DD *
*
OPTION COPY
*
INREC OVERLAY=(51:7,4,55:4,2,57:1,2,60:20,4,64:17,2,66:14,2,
25:51,8,Y4T,DATEDIFF,60,8,Y4T)
*
OUTREC BUILD=(1,50,80:X)
* |
results:
| Code: |
********************************* TOP OF DATA ****
22/01/2013 24/03/2013 -0000061
14/01/2011 24/03/2013 -0000800
30/01/2013 31/03/2013 -0000060
17/02/2013 31/03/2013 -0000042
******************************** BOTTOM OF DATA ** |
Garry |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, similar:
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(30:4,2,1,2,7,4,17,2,14,2,20,4, dates to ddmmyyyy at 30:
25:30,8,Y4W,DATEDIFF,38,8,Y4W, datediff, 8, leading sign, at 25:
26:26,7,ZD,EDIT=(TTTT),51X)) use last 4 of 8 at 25: preserving sign
//SORTIN DD *
22/01/2013 24/03/2013
14/01/2011 24/03/2013
30/01/2013 31/03/2013
17/02/2013 31/03/2013
22/01/2016 24/03/2013
14/01/2014 24/03/2013
30/01/2016 31/03/2013
17/02/2016 31/03/2013
|
Gives:
| Code: |
22/01/2013 24/03/2013 -0061
14/01/2011 24/03/2013 -0800
30/01/2013 31/03/2013 -0060
17/02/2013 31/03/2013 -0042
22/01/2016 24/03/2013 +1034
14/01/2014 24/03/2013 +0296
30/01/2016 31/03/2013 +1035
17/02/2016 31/03/2013 +1053 |
|
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
expat,
As Gary and Bill mentioned you can reformat the date using INREC and calculate the date difference. I assumed your LRECL=80 and RECFM=FB. IFOUTLEN=n is good choice to remove the temp fields after we are done with the calculations.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
22/01/2013 24/03/2013
14/01/2011 24/03/2013
30/01/2013 31/03/2013
17/02/2013 31/03/2013
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=80,IFTHEN=(WHEN=INIT,
OVERLAY=(81:7,4,4,2,1,2,X,20,4,17,2,14,2,
25:81,8,Y4T,DATEDIFF,90,8,Y4T))
//* |
Bill,
Any specific reason for only 4 Bytes? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It was the requirement :-)
I added the sign "for nothing". |
|
| Back to top |
|
 |
expat
Global Moderator

Joined: 14 Mar 2007 Posts: 8798 Location: Welsh Wales
|
|
|
|
Thanks guys,
It's really good to get the methodology behind the solution.
Old dog still learning new tricks  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|