1,880 pts.
 Get last day of previous month
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
ASKED: November 21, 2012  5:21 AM
UPDATED: November 21, 2012  2:19 PM

Answer Wiki:
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  
Last Wiki Answer Submitted:  November 21, 2012  2:19 pm  by  Michael Tidmarsh   11,380 pts.
All Answer Wiki Contributors:  Michael Tidmarsh   11,380 pts. , CharlieBrowne   32,785 pts. , RamvishakRamesh   1,880 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 107,735 pts.

 

Using RPG I’d subtract today’s day from today’s date:<blockquote>DateField = %Date() – %Days(%Subdt(%Date(): *Days));</blockquote>

 5,670 pts.

 

I just dearly love this editor.</sarcasm>

 5,670 pts.

 

And in SQL …
SELECT last_Day(Current_Date – 1 month)
FROM “SYSIBM”.SYSDUMMY1

 44,070 pts.

 

Be aware that the SQL LAST_DAY() function became available in i 6.1. — Tom

 107,735 pts.

 

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 pts.

 

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

 107,735 pts.