Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To find the month of a date

Status
Not open for further replies.

9August84

Programmer
Apr 15, 2009
8
IN
Hi all,
Is there any way to find the month of any date.
The Date('Month') gives only the month of current date.
I would like to get the month of any date (eg: 06/15/2009) in the MON format. Please help.

-Arasi

 
You can make your own function, which returns you month e.g.
Code:
[COLOR=#0000ff]/*** main                ***/[/color]
usdate [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'06/15/2009'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Month of US date '"[/color]usdate[COLOR=#ff00ff]"' is:"[/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#008080]month_of_usdate([/color]usdate[COLOR=#008080])[/color]
[COLOR=#804040][b]exit[/b][/color]

[COLOR=#0000ff]/*** procedures/functons ***/[/color]
[COLOR=#008080]month_of_usdate[/color]: [COLOR=#804040][b]procedure[/b][/color]
  [COLOR=#804040][b]parse arg[/b][/color] usdate
  month [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]substr(strip([/color]usdate[COLOR=#008080])[/color][COLOR=#804040][b],[/b][/color]1[COLOR=#804040][b],[/b][/color]2[COLOR=#008080])[/color]
  [COLOR=#804040][b]return[/b][/color] month
Output:
Code:
Month of US date '06/15/2009' is: 06
 
Hi, thank you for the response.
But all I wanted is month in MON format. ie 06 as JUN.
 
Ok, you can easily improve the above function so,
that it returns
JAN for 01
...
JUN for 06
...
or whatever you want
 
/* REXX */
Parse Value '06/15/2009' With mm '/' dd '/' ccyy .
datem = Date('M',ccyy||mm||dd,'S')
Say datem
 
Hi kevinpink,

I tried your approach. It works on windows, but doesn't work on AS/400, I got an Error
Code:
        3 +++   datem = Date('M', ccyy||mm||dd, 'S');  
   Error in line 3: Incorrect call to routine.

The REXX function DATE on AS/400 doesn't support the conversion from one date format to another, therefore for me would work only something this
Code:
[COLOR=#0000ff]/*** main                ***/[/color]
usdate [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'06/15/2009'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Month of US date '"[/color]usdate[COLOR=#ff00ff]"' is:"[/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#008080]month_of_usdate([/color]usdate[COLOR=#008080])[/color]

usdate [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'06/15/2009'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Month of US date '"[/color]usdate[COLOR=#ff00ff]"' is:"[/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#008080]month_of_usdate([/color]usdate[COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]'NUM'[/color][COLOR=#008080])[/color]

usdate [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'13/15/2009'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Month of US date '"[/color]usdate[COLOR=#ff00ff]"' is:"[/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#008080]month_of_usdate([/color]usdate[COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]'NUM'[/color][COLOR=#008080])[/color]

usdate [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'13/15/2009'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Month of US date '"[/color]usdate[COLOR=#ff00ff]"' is:"[/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#008080]month_of_usdate([/color]usdate[COLOR=#008080])[/color]
[COLOR=#804040][b]exit[/b][/color]

[COLOR=#0000ff]/*** procedures/functons ***/[/color]
[COLOR=#008080]month_of_usdate[/color]: [COLOR=#804040][b]procedure[/b][/color]
  [COLOR=#804040][b]parse arg[/b][/color] usdate[COLOR=#804040][b],[/b][/color] format
  month [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]substr(strip([/color]usdate[COLOR=#008080])[/color][COLOR=#804040][b],[/b][/color]1[COLOR=#804040][b],[/b][/color]2[COLOR=#008080])[/color]
  [COLOR=#804040][b]if[/b][/color] format [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'NUM'[/color][COLOR=#804040][b] then[/b][/color]
    [COLOR=#804040][b]if[/b][/color] month [COLOR=#804040][b]>=[/b][/color] 1 [COLOR=#804040][b]&[/b][/color] month [COLOR=#804040][b]<=[/b][/color] 12[COLOR=#804040][b] then[/b][/color]
      retval [COLOR=#804040][b]=[/b][/color] month
[COLOR=#804040][b]    else[/b][/color]
      retval [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'ERROR'[/color] 
[COLOR=#804040][b]  else [/b][/color]
  [COLOR=#804040][b]do[/b][/color] 
    months. [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'ERROR'[/color]
    months.01 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'JAN'[/color]
    months.02 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'FEB'[/color]
    months.03 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'MAR'[/color]
    months.04 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'APR'[/color]
    months.05 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'MAY'[/color]
    months.06 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'JUN'[/color]
    months.07 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'JUL'[/color]
    months.08 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'AUG'[/color]
    months.09 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'SEP'[/color]
    months.10 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'OKT'[/color]
    months.11 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'NOV'[/color]
    months.12 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'DEC'[/color]
    retval [COLOR=#804040][b]=[/b][/color] months.month
  [COLOR=#804040][b]end[/b][/color]
  [COLOR=#0000ff]/* return value */[/color]
  [COLOR=#804040][b]return[/b][/color] retval
Output
Code:
Month of US date '06/15/2009' is: JUN
Month of US date '06/15/2009' is: 06
Month of US date '13/15/2009' is: ERROR
Month of US date '13/15/2009' is: ERROR
 
Actually, that's z/OS TSO/E REXX Code. Interesting that it doesn't work in another IBM O/S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top