Page 1 of 1

convert date using SORT

PostPosted: Wed Oct 31, 2012 9:04 am
by ranga_subham
Hi,

I have a file (LRECL=80, RECFM=FB) with some data as shown below:

----+----1----+----2----+----3
BOLTEN 20101204
TANGRA 20110217
MANTRI 20090927


Expected Output:
BOLTEN 2010-12-04
TANGRA 2011-02-17
MANTRI 2009-09-27


I would like to know how to convert the date appearing in CCYYMMDD format to CCYY-MM-DD format (with hyphens in between values). Please help.

Thanks.

Re: convert date using SORT

PostPosted: Wed Oct 31, 2012 11:31 am
by Pandora-Box
Hi,

You can use the below code

SORT FIELDS=COPY
OUTREC FIELDS=(1:1,7,8:8,4,12:C'-',13:12,2,15:'-',16:14,2)

Re: convert date using SORT

PostPosted: Wed Oct 31, 2012 3:51 pm
by ranga_subham
Thanks for the idea........

May I know how to change YYMMDD to YYYY-MM-DD format please?

Re: convert date using SORT

PostPosted: Wed Oct 31, 2012 7:57 pm
by dick scherrer
Hello,

You first need to determine the rule for which dates are 19xx and which are 20xx.

Re: convert date using SORT

PostPosted: Thu Nov 01, 2012 6:09 pm
by ranga_subham
hi, all are 20xx only....no 19xx !

Thanks.

Re: convert date using SORT

PostPosted: Thu Nov 01, 2012 6:19 pm
by NicC
Well then, just include '20' i the items to build from

Re: convert date using SORT

PostPosted: Sun Nov 04, 2012 8:29 am
by ranga_subham
finally got it by using Y2S in OUTREC :D

Re: convert date using SORT

PostPosted: Sun Nov 04, 2012 8:39 am
by dick scherrer
Hello,

That is cool - good job looking as so many do not :)

Just curious why you did not try the suggestion from Nic? Might have been running a couple of days ago.

It really is good that you persisted and found what you were looking for in the manual! We highly encurage this. ;)

d