Date calculation using a variable

30 pts.
Tags:
AS/400
iSeries
RPG
This is the original standard date calculation I was using.  I need to change the number of months to a variable that I'm getting from a DTAARA.  Value is zoned.  

The error I get isDate, Time or Timestamp value is not valid.  I can't find a way to change the one or two digit value to a 'date' field Data area value us currently alpha and defined '12'. I change the value to %Dec in the program. The NHSNDDTE is an 8 0 zoned value in the format 2013120.

Any ideas at all  

$WrkSndDat = %Dec(%Date(NHSNDDTE: *ISO) + %Months(12));

Software/Hardware used:
ISeries RPG Free Format

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb

    I'm just a little confused ..

    1.  What is actually in your data area -- show us the value, and the type

    2.  What is NHSNDDTE show us the value or some values and the type/size

    3.  What type/size is $WrkSndDat

     

    49,850 pointsBadges:
    report
  • badspeller

    Data area is currently defined as alpha 2 and is set to '12'.

    I change the value to %Dec in the program

    NHSNDDTE is defined 8 0 zoned and is formated 20131201.  $WrkSndDat is defined the same way.

    30 pointsBadges:
    report
  • philpl1jb

    Hope this helps.

    The formula you provided seems to work fine.

    But since you're getting a character type and %month requires a numeric type, I had to convert it.

    D $WrkSndDat      s              8S 0
    D NHSNDDTE        s              8S 0 inz(20131201)
    D OFFSET          s              2A   inz('12')

    /free
    //  $WrkSndDat = %Dec(%Date(NHSNDDTE: *ISO) + %Months(12));
    $WrkSndDat = %Dec(%Date(NHSNDDTE: *ISO) +
    %Months(%dec(offset:2:0)));
    dsply $WrkSndDat;
    *inlr = *on;
    /end-free


    49,850 pointsBadges:
    report
  • badspeller

    That didn't work.  What I did finally do was use %Int   

    %Months(%Int(%Subst(offset:1:2))));


     

    30 pointsBadges:
    report
  • philpl1jb
    Thanks for the feedback ..
    49,850 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following