How to get end of month date in progress 4gl
Asked Answered
S

11

7

How can I get the last day of the month in progress 4gl?

Strophic answered 19/6, 2012 at 4:29 Comment(0)
D
15
/* the last day of this month is one day less than the first day of next month
 *
 * so add one month to the first day of this month and then subtract one day.
 *
 */

function lastDay returns date ( input d as date ):

  return add-interval( date( month( d ), 1, year( d )), 1, "month" ) - 1.

end.
Damron answered 19/6, 2012 at 7:39 Comment(1)
add-interval() requires version 10 or better.Damron
M
2
DEF VAR d-Dataa AS DATE NO-UNDO FORMAT "99/99/9999".

DEF VAR c-Datai AS CHAR NO-UNDO.

DEF VAR d-Datai AS DATE NO-UNDO FORMAT "99/99/9999".

DEF VAR c-Dataf AS CHAR NO-UNDO.

DEF VAR d-Dataf AS DATE NO-UNDO FORMAT "99/99/9999".

d-Dataa=TODAY.

c-Datai=("01/" + STRING(MONTH(d-Dataa),"99/") + STRING(YEAR(d-Dataa),"9999")). 

d-Datai=DATE(c-Datai).

IF MONTH(d-Dataa) = 12  THEN
c-Dataf="01/01/" + STRING(YEAR(d-Dataa) + 1,"9999").    

ELSE

c-Dataf=STRING(DAY(d-Datai),"99/") + STRING(MONTH(d-Dataa)+ 1,"99/") + STRING(YEAR(d-Dataa),"9999").

d-Dataf=DATE(c-Dataf) - 1.

MESSAGE

"Dia Atual: " STRING(d-Dataa, "99/99/9999") SKIP
"Primeiro dia do Mês: " c-Datai SKIP
"Ultimo dia do Mês: " STRING(d-Dataf, "99/99/9999") SKIP 

VIEW-AS ALERT-BOX
Manfred answered 9/8, 2017 at 14:38 Comment(0)
E
1

If you don't have "interval" on your platform - this'll do just as well:

DEFINE VARIABLE start-date      AS DATE         NO-UNDO.
DEFINE VARIABLE end-of-month    AS DATE         NO-UNDO.

ASSIGN
    start-date = DATE(2, 15, 2012)
    .

ASSIGN
    end-of-month = DATE(MONTH(start-date), 20, YEAR(start-date)) + 15
    end-of-month = end-of-month - DAY(end-of-month)
    .
Every answered 19/6, 2012 at 13:23 Comment(1)
This fails if your start-date is 3/15/2012.Damron
M
1
DEF VAR dt-ref          AS DATE     NO-UNDO.

DEF VAR dt-end-of-month AS DATE     NO-UNDO.

ASSIGN dt-ref = DATE(2,12,2012)

    .

ASSIGN dt-ref          = dt-ref + 33

       dt-end-of-month = DATE(MONTH(dt-ref),1,YEAR(dt-ref)) - 1.
Mccaffrey answered 9/8, 2012 at 14:15 Comment(0)
S
1

The easiest way is to use ADD-INTERVAL function.

ldEndDate = ADD-INTERVAL(ldBeginDate, 1, "months") - 1.
Specie answered 1/7, 2014 at 7:44 Comment(0)
S
0
PROCEDURE getEndOfMonth:
    DEFINE INPUT PARAMETER lv-date AS DATE.
    DEFINE OUTPUT PARAMETER lv-monthEnd AS DATE.

    lv-monthEnd = DATE(MONTH(lv-date), 31, YEAR(lv-date)) NO-ERROR.
    IF lv-monthEnd = ? THEN DO:
        lv-monthEnd = DATE(MONTH(lv-date), 30, YEAR(lv-date)) NO-ERROR.            
        IF lv-monthEnd = ? THEN DO:
            lv-monthEnd = DATE(MONTH(lv-date), 29, YEAR(lv-date)) NO-ERROR.            
            IF lv-monthEnd = ? THEN
                lv-monthEnd = DATE(MONTH(lv-date), 28, YEAR(lv-date)) NO-ERROR.
        END.
    END. 
END.
Strophic answered 19/6, 2012 at 4:29 Comment(0)
K
0

An easy one, go the last possible day of the current month, if it fails the last day is the previous one:

def var i as int.

def var v_eom as date.


Do i = 27 to 31:

   v_eom = date(month(today), i, year(today)) no-error.

   If error-status:error then do:

       v_eom = date(month(today), (i - 1), year(today)) no-error.

       leave.

   End.

End.
Kutz answered 30/8, 2013 at 13:59 Comment(0)
W
0

DEFINE VAR date1 AS DATE INIT 12/12/2015 .

DEFINE VAR datelast AS INT .

DEFINE VAR mont AS int.

 mont      = ( MONTH (date1) + 1).

 IF mont > 12 THEN 
 DO:
   datelast = 31.
 END.
 ELSE
 DO:
     datelast  = (DATE(STRING (1) + "/" +   (STRING(mont)) + "/" + STRING( YEAR(date1))) - DATE(STRING((1)) + "/" + STRING(month(date1)) + "/" + STRING( YEAR(date1)))). 
 END.

MESSAGE datelast   VIEW-AS ALERT-BOX INFO BUTTONS OK.
Weatherbound answered 22/4, 2014 at 9:49 Comment(0)
P
0

DEFINE VARIABLE given-date AS DATE NO-UNDO .

PROMPT-FOR given-date.

DISP DAY(add-interval( date( month( INPUT given-date), 1, year( INPUT given-date)), 1, "month" ) - 1) label "Lastdate".

Postobit answered 24/4, 2017 at 7:34 Comment(0)
T
0

This Should do it.

DEFINE VARIABLE InputDate           AS DATE        NO-UNDO.
DEFINE VARIABLE OutputDate          AS DATE        NO-UNDO.

IF MONTH(InputDate) = 12 THEN
    ASSIGN OutputDate = DATE(1,1,(YEAR(InputDate) + 1 ) ) - 1 .
ELSE 
    ASSIGN OutputDate = DATE((MONTH(InputDate) + 1 ), 1,YEAR(InputDate) ) - 1.
Tacet answered 6/4, 2018 at 11:55 Comment(0)
D
0

This solution should provide you the last date for any month.

DEFINE VARIABLE InputDate           AS DATE        NO-UNDO.
DEFINE VARIABLE OutputDate          AS DATE        NO-UNDO.

ASSIGN OutputDate = DATE(((MONTH(InputDate) MOD 12) + 1 ),1,YEAR(InputDate)) - 1.
Donte answered 26/10, 2023 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.