IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Convert Timestamp Value


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mrdinesh

New User


Joined: 23 Sep 2006
Posts: 24
Location: India

PostPosted: Thu May 05, 2016 6:01 pm
Reply with quote

Hi,

I have a requirement to convert a Datetime format into another timestamp format.

For Example

Input File:

Code:
Jun 12 2014  6:36:04:423AM
Oct 11 2013  9:49:00:826PM
Jan 12 2015 12:38:03:376PM
Jan 21 2015  4:54:08:743PM


Should get converted into as

Output File:

Code:
20140612063604423
20131011214900826
20150112123803376
20150121165408743


Thanks.
Back to top
View user's profile Send private message
mrdinesh

New User


Joined: 23 Sep 2006
Posts: 24
Location: India

PostPosted: Thu May 05, 2016 6:03 pm
Reply with quote

I tried searching through the forum for example but couldnot find anything relevant for this. I was thinking of using IFTHEN in condition in the OUTREC statement. Thought of checking if there are any other efficient methods are available.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Fri May 06, 2016 1:06 am
Reply with quote

Use inout to convert month to a number and then translate AM/PM by adding 12 to the hours except 12 and build as per output.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri May 06, 2016 5:29 pm
Reply with quote

Most of what you want is simple rearranging. To change the months to numbers, look at CHANGE, which will be more effective than FINDREP with INOUT. For your PM you will need to add 12, with the output of ZD with a length of two, or use an EDIT (like TT).

The potential leading space in the hours can be changed to a '0' with another CHANGE, with a default for non-space of the original value.
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Mon May 09, 2016 7:24 am
Reply with quote

This code may help you.
Code:

OPTION COPY                                                     
INREC IFTHEN=(WHEN=INIT,OVERLAY=(1,3,                           
                                 CHANGE=(3,C'JAN',C'01',         
                                           C'FEB',C'02',         
                                           C'MAR',C'03',         
                                           C'APR',C'04',         
                                           C'MAY',C'05',         
                                           C'JUN',C'06',         
                                           C'JUL',C'07',         
                                           C'AUG',C'08',         
                                           C'SEP',C'09',         
                                           C'OCT',C'10',         
                                           C'NOV',C'11',         
                                           C'DEC',C'12'),       
                                 NOMATCH=(C'00'))),             
IFTHEN=(WHEN=INIT,BUILD=(8,4,1,2,5,2,13,2,FS,ZD,16,2,19,2,22,3))
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Mon May 09, 2016 8:18 am
Reply with quote

Missed +12 addition.

Code:

OPTION COPY                                                         
INREC IFTHEN=(WHEN=INIT,OVERLAY=(1,3,                               
                                 CHANGE=(3,C'JAN',C'01',           
                                           C'FEB',C'02',           
                                           C'MAR',C'03',           
                                           C'APR',C'04',           
                                           C'MAY',C'05',           
                                           C'JUN',C'06',           
                                           C'JUL',C'07',           
                                           C'AUG',C'08',           
                                           C'SEP',C'09',           
                                           C'OCT',C'10',           
                                           C'NOV',C'11',           
                                           C'DEC',C'12'),           
                                 NOMATCH=(C'00'),                   
                                 13:13,2,FS,ZD,LENGTH=2)),         
      IFTHEN=(WHEN=(25,2,CH,EQ,C'PM',AND,13,2,CH,NE,C'12'),         
                        OVERLAY=(13:13,2,ZD,ADD,+12,LENGTH=3)),     
      IFTHEN=(WHEN=(25,2,CH,EQ,C'AM',AND,13,2,CH,EQ,C'12'),         
                        OVERLAY=(13:C'00')),                       
      IFTHEN=(WHEN=NONE,OVERLAY=(13:13,2))                         
OUTREC BUILD=(8,4,1,2,5,2,13,2,16,2,19,2,22,3)       
Back to top
View user's profile Send private message
mrdinesh

New User


Joined: 23 Sep 2006
Posts: 24
Location: India

PostPosted: Mon May 09, 2016 10:02 am
Reply with quote

Hi Magesh,

Thanks for your Help. I was able to convert the timestamp with a different Sortcard, but similar to the one you posted.

Code:

 OPTION COPY                                                           
 INREC  IFTHEN=(WHEN=(05,1,CH,EQ,C' '),OVERLAY=(05:C'0'),HIT=NEXT),     
        IFTHEN=(WHEN=(13,1,CH,EQ,C' '),OVERLAY=(13:C'0'),HIT=NEXT),     
        IFTHEN=(WHEN=(25,2,CH,EQ,C'PM',AND,13,2,CH,NE,C'12'),           
                OVERLAY=(13:13,2,ZD,ADD,+12,TO=ZD,LENGTH=2),HIT=NEXT), 
        IFTHEN=(WHEN=(25,2,CH,EQ,C'AM',AND,13,2,CH,EQ,C'12'),           
                OVERLAY=(13:C'00'))                                     
 OUTREC BUILD=(8,4,1,3,CHANGE=(2,C'Jan',C'01',C'Feb',C'02',             
               C'Mar',C'03',C'Apr',C'04',C'May',C'05',C'Jun',C'06',     
               C'Jul',C'07',C'Aug',C'08',C'Sep',C'09',C'Oct',C'10',     
               C'Nov',C'11',C'Dec',C'12'),NOMATCH=(C'  '),             
               5,2,13,2,16,2,19,2,22,3)                                 


Just have one small question - Is there any way to ignore the lower cases. In this I have to build the sort with only lower cases since the input file contains smaller cases. (This is not a real big issue, but anyhow the above sort solves the requirement).


Thanks.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon May 09, 2016 10:28 am
Reply with quote

Why do you want the NOMATCH for the monts? What's your actual problem with the months and lower-case?

If you use CHANGE for the blank parts o the hours (first character of time) won't that do it? Then your IFTHEN is just for PM less than 12?

Why jam all your code together like that? You worked from magesh23586's example, which has better formatting than most, then decided to make it harder to read and change?

If you follow my suggestions, you'll greatly reduce the amount of code. Why not make what is left easier to read?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Timestamp difference and its average ... DB2 11
Search our Forums:

Back to Top