如何获得正在进行的月结束日期4gl

时间:2012-06-19 04:29:50

标签: progress-4gl

如何才能获得正在进行的月份的最后一天4gl?

10 个答案:

答案 0 :(得分:10)

/* 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.

答案 1 :(得分: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

答案 2 :(得分: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.

答案 3 :(得分: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.

答案 4 :(得分:0)

如果你没有" interval"在您的平台上 - 这也会做得很好:

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)
    .

答案 5 :(得分:0)

一个简单的,一个月的最后一天,如果它失败,最后一天是前一个:

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.

答案 6 :(得分: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.

答案 7 :(得分:0)

最简单的方法是使用ADD-INTERVAL函数。

ldEndDate = ADD-INTERVAL(ldBeginDate, 1, "months") - 1.

答案 8 :(得分:0)

DEFINE VARIABLE给定日期AS DATE NO-UNDO。

PROMPT-FOR给定日期。

DISP DAY(添加间隔(日期(月份(INPUT给定日期),1年(INPUT给定日期)),1,"月份") - 1)标签" Lastdate"

答案 9 :(得分:0)

这应该这样做。

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.