我怎样才能得到正在进行的4gl一个月的最后一天?
问问题
12857 次
10 回答
13
/* 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.
于 2012-06-19T07:39:36.833 回答
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
于 2017-08-09T14:38:18.687 回答
1
如果您的平台上没有“间隔” - 这也可以:
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)
.
于 2012-06-19T13:23:21.490 回答
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.
于 2012-08-09T14:15:16.423 回答
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.
于 2012-06-19T04:29:50.107 回答
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.
于 2013-08-30T13:59:13.877 回答
0
将 VAR date1 定义为 DATE INIT 12/12/2015 。
DEFINE VAR datelast AS INT 。
将 VAR mont 定义为 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.
于 2014-04-22T09:49:55.683 回答
0
最简单的方法是使用 ADD-INTERVAL 函数。
ldEndDate = ADD-INTERVAL(ldBeginDate, 1, "months") - 1.
于 2014-07-01T07:44:31.347 回答
0
DEFINE VARIABLE given-date AS DATE NO-UNDO 。
PROMPT-FOR 给定日期。
DISP DAY(add-interval( date( month( INPUT given-date), 1, year( INPUT given-date)), 1, "month" ) - 1) 标签 "Lastdate"。
于 2017-04-24T07:34:54.163 回答
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.
于 2018-04-06T11:55:04.423 回答