×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

To find the month of a date

To find the month of a date

To find the month of a date

(OP)
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

RE: To find the month of a date

You can make your own function, which returns you month e.g.

CODE

/*** main                ***/
usdate = '06/15/2009'
say "Month of US date '"usdate"' is:",
month_of_usdate(usdate)
exit

/*** procedures/functons ***/
month_of_usdate: procedure
  parse arg usdate
  month = substr(strip(usdate),1,2)
  return month
Output:

CODE

Month of US date '06/15/2009' is: 06

RE: To find the month of a date

(OP)
Hi, thank you for the response.
But all I wanted is month in MON format. ie 06 as JUN.

RE: To find the month of a date

Ok, you can easily improve the above function so,
that it returns
JAN for 01
...
JUN for 06
...
or whatever you want

RE: To find the month of a date

/* REXX */                                         
Parse Value '06/15/2009' With mm '/' dd '/' ccyy .
datem = Date('M',ccyy||mm||dd,'S')                 
Say datem                                           

RE: To find the month of a date

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

/*** main                ***/
usdate = '06/15/2009'
say "Month of US date '"usdate"' is:",
month_of_usdate(usdate)

usdate = '06/15/2009'
say "Month of US date '"usdate"' is:",
month_of_usdate(usdate,'NUM')

usdate = '13/15/2009'
say "Month of US date '"usdate"' is:",
month_of_usdate(usdate,'NUM')

usdate = '13/15/2009'
say "Month of US date '"usdate"' is:",
month_of_usdate(usdate)
exit

/*** procedures/functons ***/
month_of_usdate: procedure
  parse arg usdate, format
  month = substr(strip(usdate),1,2)
  if format = 'NUM' then
    if month >= 1 & month <= 12 then
      retval = month
    else
      retval = 'ERROR'
  else
  do
    months. = 'ERROR'
    months.01 = 'JAN'
    months.02 = 'FEB'
    months.03 = 'MAR'
    months.04 = 'APR'
    months.05 = 'MAY'
    months.06 = 'JUN'
    months.07 = 'JUL'
    months.08 = 'AUG'
    months.09 = 'SEP'
    months.10 = 'OKT'
    months.11 = 'NOV'
    months.12 = 'DEC'
    retval = months.month
  end
  /* return value */
  return 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
 

RE: To find the month of a date

Actually, that's z/OS TSO/E REXX Code. Interesting that it doesn't work in another IBM O/S.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close