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

REXX to format the date


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
balaji81_k

Active User


Joined: 29 Jun 2005
Posts: 155

PostPosted: Thu Jul 05, 2012 5:56 pm
Reply with quote

Hi ,

Iam New to REXX and i have a question on formating the date .

My input date value will be like "201207"

output should be like "July2012".

Iam also refering the manuals to get it from that , if any one could help me out it would be great help for me.

Thanks
Balaji K
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Jul 05, 2012 6:06 pm
Reply with quote

It'll be a little while before I can test; however, this code fragment should get you started:
Code:
input_date = input_date || "01"
year = substr(input_date,1,4)
output_date = date(,input_date,"Month")
output_date = output_date || year
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Jul 05, 2012 6:40 pm
Reply with quote

Modified Akatsukami's code

Code:

INPUT_DATE  = "201207"
OUTPUT_DATE = SUBSTR(INPUT_DATE,5,2)|| "/" || "01" || "/" || ,
              SUBSTR(INPUT_DATE,3,2)
OUTPUT_DATE = DATE('M',OUTPUT_DATE,'USA')
OUTPUT_DATE = OUTPUT_DATE || SUBSTR(INPUT_DATE,1,4)
SAY OUTPUT_DATE
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Thu Jul 05, 2012 7:54 pm
Reply with quote

You could also look at using the Date builtin to convert from one date format to the other. Or, much more simply, have a stem with the month abbrevaitions, extract the month number from the date and use that as in index into the stem. To go the other way you can have a stem of month numbers indexed by the month NAME.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Jul 05, 2012 8:02 pm
Reply with quote

Nic Clouston wrote:
To go the other way you can have a stem of month numbers indexed by the month NAME.


Seems to be best solution out of all "Atleast for me"
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Thu Jul 05, 2012 10:19 pm
Reply with quote

but I have forgotten the syntax - I will have to look for a bit of code that was probably written in australia and, therefore, is 16 years old - at least
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Jul 05, 2012 10:29 pm
Reply with quote

Nah that wont be needed I will do it fot you

Code:
Mon.01="January"
.
.
Mon.12="December"
In_date ="201207"
I=SUBSTR(IN_DATE,5,2)
OUT_DATE=MON.I||SUBSTR(IN_DATE,1,4)
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Jul 06, 2012 2:26 am
Reply with quote

Oh - that is dead simple. I was referring to the fact that I need to check the syntax for accessing the stem by using a 'string' as the key sort of like:
Code:

m.jan = 1
m.feb = 2
:
m.dec = 12

monthnum= m.jan

should shove 1 into monthnum but I have not got the syntax quite right and I don't have my work USB plugged in.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2546
Location: Silicon Valley

PostPosted: Fri Jul 06, 2012 4:14 am
Reply with quote

If I understand this tread correctly, the code:
Code:
m.jan = 1
m.feb = 2
:
m.dec = 12


is a tangent and not particularly useful to solve the OP's problem.
Back to top
View user's profile Send private message
Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Fri Jul 06, 2012 6:29 am
Reply with quote

Code:

/*  No stems No substrings .... just for laughs
     Not right/wrong/better   just different   [and not tested ]
*/
Months='January February ... December'
mm=right(in_date,2)
yy=left(in_date,4)
answer=word(months,mm)||yy

Back to top
View user's profile Send private message
balaji81_k

Active User


Joined: 29 Jun 2005
Posts: 155

PostPosted: Fri Jul 06, 2012 10:41 am
Reply with quote

Many Thanks to Every one !!!!!!!!!!!!!!

who shared for this topic .. i put the code as suggested it working fine.


Thanks
Balaji K icon_biggrin.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 06, 2012 11:32 am
Reply with quote

Peter Nancollis

Exactly the same method I have used in the past - good shout
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
Search our Forums:

Back to Top