• Subject: RE: last day of month (was MIDRANGE-L Digest V2 #1546)
  • From: Jon Erickson <jerickson@xxxxxxx>
  • Date: Fri, 15 Oct 1999 12:29:18 -0700

Kewl,

In response to use of numeric fields,.. If the parameters are character, you
can define the *Iso date sub-fields as character, and you could use MOVE
instead of Eval to eliminate data type errors, keeping in mind, same field
lengths.

Of course I haven't tested any Date Opcode performances...

Regards,
Jon

                -----Original Message-----
                From:   bmorris@ca.ibm.com [mailto:bmorris@ca.ibm.com]
                Sent:   Friday, October 15, 1999 9:20 AM
                To:     MIDRANGE-L@midrange.com
                Subject:        RE: last day of month (was MIDRANGE-L Digest
V2 #1546)




                >Date: Thu, 14 Oct 1999 09:16:48 -0700
                >From: Jon Erickson <jerickson@800.com>
                >
                >Correct me if I'm wrong,
                > ...
                >
                >d                 DS
                >d Isodate                         d   DatFmt(*Iso) Inz
                >d  Isoyyyy                       4  0 Overlay(Isodate)
                >d  Isomm                         2  0 Overlay(Isodate:6)
                >
                >c                   Eval      Isoyyyy = Pyear
                >c                   Eval      Isomm = Pmonth
                >Add 1 month via ADDDUR
                >c                   AddDur    1:*Months     Isodate
                >
                >Subtract 1 day via SUBDUR
                >c                   SubDur    1:*Days       Isodate

                Sure, that will work.  I was discussing Jon's code to solve
the general case of
                getting the last day of the month containing a given date.

                Jon's code can be made to run a bit more quickly using
overlays (you can get rid
                of the extract by just setting the days part to "01").
Maybe that's a good
                idea,
                maybe not - it seems to me that using overlays makes the
code a bit more
                complex.

                If you start with numeric year and month as in your example,
your way is as good
                as any.

                Hmm, I just thought of a way to use numeric year and month
input avoiding
                overlays, with a single adddur:

                D date            s               d       datfmt(*iso)
inz(D'0001-01-31')
                 * Find the number of months after 0001-01 for the given
year and month
                 * E.g. for 0002-03, there are 12 + 1 months
                C                   eval      Pmonth = ((Pyear - 1) * 12) +
(Pmonth - 1)
                 * Add them to Jan 31, 0001.  Month-end adjustment will fix
up any results
                 * where the number of days in the month is less than 31.
                C                   adddur    Pmonth:*m     date

                With date operations, the contest should be regarding the
number of date
                opcodes,
                not the number of statements.  (Date opcodes are very
expensive.)

                Barbara Morris


                +---
                | This is the Midrange System Mailing List!
                | To submit a new message, send your mail to
MIDRANGE-L@midrange.com.
                | To subscribe to this list send email to
MIDRANGE-L-SUB@midrange.com.
                | To unsubscribe from this list send email to
MIDRANGE-L-UNSUB@midrange.com.
                | Questions should be directed to the list owner/operator:
david@midrange.com
                +---
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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

This mailing list archive is Copyright 1997-2022 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.