## Last Day of Month

5 pts.
Tags:
AS/400 date format
CLLE
Is there a routine to arrive at the exact last day of the month? *Month doesn't do it.

Thanks. We'll let you know when a new response is added.
```* Find the first day of month / last day of month
D StrDate S D
D EndDate S D
/FREE
StrDate = %date(%subst(%char(%date()):1:8) + '01':*ISO);
EndDate = StrDate + %months(1) - %days(1);
/END-FREE```

———————————————-
I keep these calculations handy, but they can be converted into procedures easily

```d PriorMonthBegin...
d s d
d PriorMonthEnd s d
d MonthBegin s d
d MonthEnd s d
*Mon = 0 ... Sun = 6
d DayOfWeek s 1p 0
d WeekDay s n
d WeekEnd s n

PriorMonthBegin = %date() - %months(1) - %days(%subdt(%date() - %months(1):*days)) + %days(1);
PriorMonthEnd = %date() - %days(%subdt(%date():*days));
MonthBegin = %date() - %days(%subdt(%date():*days)) + %days(1);
MonthEnd = %date() + %months(1) - %days(%subdt(%date() + %months(1):*days));
DayOfWeek = %rem(%diff(%date():d'0001-01-01':*days):7);
WeekDay = %rem(%diff(%date():d'0001-01-01':*days):7) < 5;
WeekEnd = %rem(%diff(%date():d'0001-01-01':*days):7) > 4;```

Kevin

=======================================================

If you are current with your OS, you can use the SQL LAST_DAY(CURRENT DATE) function. It’s not available for CL of course, but REXX can access it and report the result back out.

Tom

## Discuss This Question: 7 Replies

Thanks. We'll let you know when a new response is added.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
• // another way to get just the last day of this month EndDate = %date() + %month(1) - %subdt(%date() + %month(1):*days);
report
• ha - Great minds think alike, huh Graybeard52?
report
• Must be the facial hair !