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

Date conversion

Date conversion

Date conversion

Hello I am modifying a program that haves two integer fields one called (screen field)@CDATE and the other (field from file)RCDATE that are 6 character fields. Now my problem is is that @CDATE is *MDY format while RCDATE is in *YMD format and I'm trying to get the RCDATE format to *MDY also so when I do a :


They both have the same format.

RE: Date conversion

Use the %Date() Built-in Function.
%DATE converts the value of the expression from character, numeric, or timestamp data to type date. The converted value remains unchanged, but is returned as a date. The first parameter is the value to be converted. If you do not specify a value, %DATE returns the current system date. The second parameter is the date format for character or numeric input. Regardless of the input format, the output is returned in *ISO format.

Anyway you'd be better off defining a date field on the screen record format.



d RcDate          s              6p 0 inz(071115)
d ScreenDate      s               d   datfmt(*MDY)

C         EVAL    ScreenDate = %Date(RcDate : *YMD)

If RCDATE is '071115', ScreenDate now contains dā€™2007-11-15ā€™

RE: Date conversion

I may get some hate mail but that's OK. If you want to kick it old school, there is a little trick from back before Bill gates was just a little tadpole.

Multiply cdate by 10000.01. It will arithmetically convert mdy to ymd. To convert back use 100.0001. This is supposed to be inefficient and is not recommended. It used to be one of the ways we converted dates. The other is to use two data structures that break the fields into the month, day, and year parts. Then move the cdate parts to the rcdate parts and vice versa.

Today, I would do what Mercury2 suggested. But, there is still a lot of old code around using one of the two other methods, or both.

A little trip down memory lane.

RE: Date conversion

>>Regardless of the input format, the output is returned in *ISO format. <<

Not true.  The date format is whatever the result field is defined.  In this example, ScreenDate is defined as *MDY so will be 111507.

For the orig request:
EVAL  @CDATE = %dec(%date(RCDATE:*MDY):*YMD)

Note that this will fail if RCDATE is not a valid date.

RE: Date conversion

>>Regardless of the input format, the output is returned in *ISO format by default. <<
Although I copied this text from the ILE RPG Reference Guide, my previous posting should have read by default at the end of the sentence.
Now if both dates are 6 char fields, here's what i'd do


d RcDate          s              6a   inz('071115')    
d CDate           s              6a                    

C         EVAL    CDate = %Char(%Date(RcDate : *YMD0) : *MDY0)

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