× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I just wrote a line of code to formulate the 1st of the month for two months
back... (Free Format) I know my variable says LastMonth (the user changed
their mind, and I'm not up to speed yet! LOL)

// Calculate Selection Date to the 1st Day of two months ago.
LastMonth = %Date((%SubDt(%Date: *Y) * 10000) +
((%SubDt(%Date: *M) - 2) * 100) + 1);

On Sat, Jul 5, 2008 at 4:30 PM, RWMunday <RWMunday@xxxxxxxxxxxxx> wrote:

Booth,



-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Booth Martin
Sent: Saturday, July 05, 2008 4:33 PM

<<< Simplest way to set a date as the first of the current month >>>

A program I wrote prompted the user to key the processing year and the
quarter. One company was processed by quarter so all I needed was January
1st through March 31st. One company was processed by individual months, so
I needed to have January 1st through January 31st and on and on. For the
individual months (an abbreviated example not to scale), I did this:

* ISO Date To Calculate Beginning Date By Month
D DS
D @BegISO D DatFmt(*ISO)
ISO Date
D @BegCCYY Overlay(@BegISO :1) Like(@ISOCCYY)
ISO Century/Year
D @Dash1 1A Overlay(@BegISO :5)
Dash Character
D @BegMM Overlay(@BegISO :6) Like(@BegDD)
ISO Month
D @Dash2 Overlay(@BegISO :8) Like(@Dash1)
Dash Character
D @BegDD 2S 0 Overlay(@BegISO :9) Inz(1)
ISO Day

* Work Fields
D @BegDate1 D DatFmt(*ISO)
Beginning Date 1 ISO
D @BegDate2 D DatFmt(*ISO)
Beginning Date 2 ISO

/Free
@Dash1 = '-'; // Dash Character
@Dash2 = '-'; // Dash Character

// Populate Fields With First Quarter Month Values
When TXQUARTER = '1'; // First Quarter?
@BegMM = 1; // Processing Month Of January
@BegCCYY = TXYEAR; // Processing Year
@BegDate1 = @BegISO; // First Day Of Processing
January/Year
@EndDate1 = (@BegISO + %Months(1)) - %Days(1); // Last Day Of Processing
January/Year
@BegMM = 2; // Processing Month Of February
@BegCCYY = TXYEAR; // Processing Year
@BegDate2 = @BegISO; // First Day Of Processing
February/Year
@EndDate2 = (@BegISO + %Months(1)) - %Days(1); // Last Day Of Processing
February/Year

You could derive last month's beginning and ending dates by taking today's
date, subtract one month, move it to an ISO date field data structure,
force
1 into the month field, move that to an ISO date field, add one month and
subtract one day to get the last day of the previous month. It also takes
care of those pesky leap years with a February 29th date.



Robert Munday
Munday Software Consultants
Montgomery, AL
between gigs...

--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.