Joined: 20 May 2004 Posts: 97 Topics: 43 Location: hyderabad, India
Posted: Wed Feb 08, 2006 4:21 am Post subject: How to find the DAY difference between 2 date fields in SORT
Hi All,
I have a specific requirement :-
In DB2 we have the facility of performing Arithmetic Operations on DATE fields, like subtracting n days from a date or finding the days difference between 2 date fields .
Ex :
select current_date - date('2005-12-27') from sysibm.sysdummy1;
select current_date - 3 months from sysibm.sysdummy1;
My requirement is , can we perform the same arithmetic operations on date fields using SORT.
Specifically what I am looking for is , I have a file having 2 Date fields.
I have to extract those records from the file where days differnce between these 2 fields is less than 3 months.
Currently we are doing this using a program , but just wondering if you people have some tricks under the sleeves to do the same using SORT.
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Wed Feb 08, 2006 10:10 am Post subject:
pzmohanty,
If you are intention is to pick all records which are 3 months old (90 days) from the currrent date , then it is very simple and can be done in just 1 simple step. If you have syncsort of z/os 1.1 and higher , this 1 step JCL will give you the desired results.
The catch here is 3 months does not essentially translate to 90 days.
ex:
Code:
SELECT CURRENT DATE - 3 MONTHS
FROM SYSIBM.SYSDUMMY1;
The result is
Code:
2005-11-08
Actually Current date - (2005-11-08 ) is 92 days
If you are happy with 90 days selection then you can use the sample JCL shown above.
In any case your 3 step can actually be done in 2 just 2 steps. Can you tell me the format(yyyy-mm-dd or mm-dd-yyyy or ...) of the date in your input file. Also what format of date do you get when you run your db2 query?
Joined: 20 May 2004 Posts: 97 Topics: 43 Location: hyderabad, India
Posted: Thu Feb 09, 2006 7:16 am Post subject:
Hi Kolusu ,
Thanks for the suggestion of using SYMNAMES DD in SORT , which has significantly reduced the code complexity.
But , I think the date comparison will not work as we are comparing dates in 'MM/DD/CCYY' format. Any date comparisons with these format will behave as Character comparison.
For example , '12/28/2005' will be greater than '12/27/2006' ( which is wrong)
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Mon Oct 25, 2010 12:23 pm Post subject:
pzmohanty,
With PTF UK90025 for z/OS DFSORT V1R10 and PTF UK90026 for z/OS DFSORT V1R12(Oct, 2010), DFSORT now supports date arithmetic which can be used to calculate the number of days difference between two dates. The result is an 8-byte value consisting of a sign and 7 digits (sddddddd). If the first date is greater than or equal to the second date, the sign is + (plus). If the first date is less than the second date, the sign is - (minus).
For complete details of date arithmetic functions and other new functions see "User Guide for DFSORT PTFs UK90025 and UK90026" paper (sortugph.pdf) at:
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum