Get last day of previous month

2505 pts.
Tags:
AS/400
AS400 Date
I have a field from file which has date value as '10/07/2012' I need to get last month's last day. 1e 30/6/2012. What is the easiest way to get this?

Software/Hardware used:
AS400 date

Answer Wiki

Thanks. We'll let you know when a new response is added.

First change the DD in the date to ’01’

Your field will now have 01/07/2012

Now subtract 1 day from that date Newdate = Indate – %Days(1);

Newdate will now be 30/06/2012

 

Discuss This Question: 7  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
  • TomLiotta
    The 'Answer' above is generally okay. But we need to know what language you're using (RPG? COBOL? C? SQL? CL?) and what OS version you're running before we can be sure. We probably also need to know what data type your field is. If it's a plain character variable, it might not be handled the same as a DATE or TIMESTAMP variable. -- Tom
    125,585 pointsBadges:
    report
  • Splat
    Using RPG I'd subtract today's day from today's date:<blockquote>DateField = %Date() - %Days(%Subdt(%Date(): *Days));</blockquote>
    7,655 pointsBadges:
    report
  • Splat
    I just dearly love this editor.</sarcasm>
    7,655 pointsBadges:
    report
  • philpl1jb
    And in SQL ... SELECT last_Day(Current_Date - 1 month) FROM "SYSIBM".SYSDUMMY1
    51,355 pointsBadges:
    report
  • TomLiotta
    Be aware that the SQL LAST_DAY() function became available in i 6.1. -- Tom
    125,585 pointsBadges:
    report
  • hellofriends
    try this below code in RPG IV. it definitely works for your requirement. If you know the better than this one just share here.D @DATE1          S               D   Inz(D'2012-10-07')         D @DATE2          S               D   Datfmt(*USA)                *                                                               C                   MOVE      @DATE1        @DATE2               C                   Extrct    @DATE2:*D     Days_N            2 0C                   Eval      @DATE2 = @DATE2 - %days(Days_N)             
    35 pointsBadges:
    report
  • TomLiotta
    try this below code in RPG IV. it definitely works for your requirement.   It looks like it will work, though I didn't try it. But the C-specs can be replaced by a single /free-form statement:
       @DATE2 = @DATE1 - %days(%subdt(@DATE1:*days)) ;:
    That's essentially what Splat already said above.   Tom
    125,585 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