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
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
Using RPG I’d subtract today’s day from today’s date:<blockquote>DateField = %Date() – %Days(%Subdt(%Date(): *Days));</blockquote>
I just dearly love this editor.</sarcasm>
And in SQL …
SELECT last_Day(Current_Date – 1 month)
FROM “SYSIBM”.SYSDUMMY1
Be aware that the SQL LAST_DAY() function became available in i 6.1. — Tom
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)
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:
That’s essentially what Splat already said above.
Tom