first and last of previous month

Pickering, John (NORBORD) John.Pickering@norbord.com
Thu, 11 Nov 2004 12:44:24 -0500


To get the first date and the last of the previous month you could do
something like the code below. No attempt has been made to optimize the
defines as they will probably be such a small part of a monthly report that
any improvements would be insignificant.

You'll need to run this after the end of month that you're interested in but
before the end of the next month -- i.e. running it in November will
generate October dates.

; get the first of the current month by taking yyyymm + 01
>define d-first-of-current date &
>  = nconvert(ascii(sysdate,8)[1:6] + "01")
; get the last of the previous month by backing up one day
>define d-last-of-previous date &
>  = date(days(d-first-of-current) - 1)
; get the first of the previous month by taking yyyymm + 01
>define d-first-of-previous date &
>  = nconvert(ascii(d-last-of-previous,8)[1:6] + "01")

Regards,
JWP