View previous topic :: View next topic
|
Author |
Message |
tecnokrat Warnings : 1 Active User
Joined: 22 May 2009 Posts: 160 Location: Bangalore
|
|
|
|
Is there any solution for getting the month number from the DATE command in REXX.
i have tried using this function
Code: |
CURRENT_MONTH = SUBSTR(DATE('U'),1,2)
which would return '08' |
but if i give the month name as REL=OCT im unable to get the month number
Code: |
MONTH = SUBSTR(DATE('U','01 'REL' 2009,1,2) This is returning me an error Incorrect call to routine |
as i have gone through the DATE function
it suggests me to use in the manner
Code: |
DATE('U','01 Oct 2009') gives me result '10/01/09'
but DATE('U','01 OCT 2009') gives me incorrect result |
is there any function in rexx to get OCT in camel notation so i would be solved my problem |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Set up a stem,
Code: |
camel.0JAN = 'Jan'
.
.
.
camel.0DEC = 'Dec'
|
and use the value function to get the 'camel'ised month. And RTFM so that you don't have to come back to ask how to use the value function! |
|
Back to top |
|
|
tecnokrat Warnings : 1 Active User
Joined: 22 May 2009 Posts: 160 Location: Bangalore
|
|
|
|
let me put the question in this way,
is there any function which would return the month number
if we provide the first three chars of a month. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
NO
But it's not difficult to do it yourself is it. It took me about 3 minutes to code this up, although Prino beat me to it with an alternative.
All you need to do is to put the code in a concatenated library and change it a little to make it a called module.
Code: |
DATEIN = "01 APR 2009"
PARSE VAR DATEIN DD MM YY
IF LEFT(DD,1) = '0' THEN DD = RIGHT(DD,1)
SELECT
WHEN MM = 'JAN' then MM = 'Jan'
WHEN MM = 'FEB' then MM = 'Feb'
WHEN MM = 'MAR' then MM = 'Mar'
WHEN MM = 'APR' then MM = 'Apr'
WHEN MM = 'MAY' then MM = 'May'
WHEN MM = 'JUN' then MM = 'Jun'
WHEN MM = 'JLY' then MM = 'Jly'
WHEN MM = 'AUG' then MM = 'Aug'
WHEN MM = 'SEP' then MM = 'Sep'
WHEN MM = 'OCT' then MM = 'Oct'
WHEN MM = 'NOV' then MM = 'Nov'
WHEN MM = 'DEC' then MM = 'Dec'
OTHERWISE NOP
END
MTH = SUBSTR(DATE('U',DD MM YY,'N'),1,2) |
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
This just seems like a case situation. As long as you know what case the date function needs, program for it.
Code: |
parse var mm m1 2 m2
mm = m1 || ,
translate(m2,'abcdefghijklmnopqrstuvwxyz',,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ') |
ps. I am not sure if this any more elegant than the other solutions, but seems to be simpler to me. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
since I am becoming like a picky old lady
here is how I would do it
Code: |
datein = "01 APR 2009"
parse var datein dd mm yy
mn = wordpos(translate(mm),"JAN FEB MAR APR MAY JUN JLY AUG SEP OCT NOV DEC")
say mn |
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Enrico, I do not think your code snippet answers the right problem. I thought the problem was that the DATE('U','01 OCT 2009') function failed because it wanted a mixed case month... Oct instead of OCT. At least, that is the way I read it, and also what the other posters seemed to solve. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
let me put the question in this way,
is there any function which would return the month number
if we provide the first three chars of a month. |
it does, it does |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Doh!
I stand corrected. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
no need for that.. You can sit corrected |
|
Back to top |
|
|
tecnokrat Warnings : 1 Active User
Joined: 22 May 2009 Posts: 160 Location: Bangalore
|
|
|
|
Thanks enrico,
for solving my problem in a simpler manner
|
|
Back to top |
|
|
|