|
View previous topic :: View next topic
|
| Author |
Message |
mrdinesh
New User
Joined: 23 Sep 2006 Posts: 24 Location: India
|
|
|
|
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 |
|
 |
mrdinesh
New User
Joined: 23 Sep 2006 Posts: 24 Location: India
|
|
|
|
| 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 |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3112 Location: NYC,USA
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
magesh23586
Active User

Joined: 06 Jul 2009 Posts: 213 Location: Chennai
|
|
|
|
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 |
|
 |
magesh23586
Active User

Joined: 06 Jul 2009 Posts: 213 Location: Chennai
|
|
|
|
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 |
|
 |
mrdinesh
New User
Joined: 23 Sep 2006 Posts: 24 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|