View previous topic :: View next topic
|
Author |
Message |
balaji81_k
Active User
Joined: 29 Jun 2005 Posts: 155
|
|
|
|
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 |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
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 |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2596 Location: Silicon Valley
|
|
|
|
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 |
|
|
Peter Nancollis
New User
Joined: 15 Mar 2011 Posts: 47 Location: UK
|
|
|
|
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 |
|
|
balaji81_k
Active User
Joined: 29 Jun 2005 Posts: 155
|
|
|
|
Many Thanks to Every one !!!!!!!!!!!!!!
who shared for this topic .. i put the code as suggested it working fine.
Thanks
Balaji K |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Peter Nancollis
Exactly the same method I have used in the past - good shout |
|
Back to top |
|
|
|