"Last Day of the Month" and Date-to-Char Formatting

doom1701

Member
I've got a process that I run manually right now on the first of every month. Right now I feed it two dates--the last day of the previous month, and the last day of the current month one year earlier. I have to format it with dashes between each segment, and a two digit year. Here's what I need to put in today:

4-30-10
5-31-09

I'm guessing there's a way I can generate this in code, and just setup a scheduled job instead of running it manually. It's obviously not a huge task...but manual none the less.
 

UncleNel

New Member
I see at least two way of handling your requirement: 1) string function to format the date, e.g. string(today /*some date field*/, "99-99-99"). This is assuming that the date format is "MM/DD/YYYY".
2) If you need to break down the date into individual components, you can use the substitute function, e.g. substitute("&1-&2-&3", string(month(today),"99"), string(day(today),"99"),string(year(today),"99")).

I do not understand you question regarding running it manually versus scheduled, and how this ties into the date formatting requirement? Please explain in more detail.
 

doom1701

Member
The part that makes it difficult (for me) to schedule is that I need to calculate those two specific dates--the end of the previous month (04-30-10), and the end of the current month, one year previous (05-31-09). These changes every month--on June 1, I'll need to plug in 05-31-10 and 06-30-09. I know how do do those in .Net, but I've never had to do them in Progress (and I'd rather not try to do a .Net app and all the required connectivity for something like this).
 

GregTomkins

Active Member
I'm not sure if this is what you are asking, but to get the last day of a month, simply and reliably, assuming you don't care about business days etc... just take the first day of the next month and subtract 1.
 

doom1701

Member
That would work for the last day of the previous month (assuming I run this on the first on the month, which, on a scheduler, shouldn't be a problem). I still need to get the last day of the current month one year previous, though.
 

vinod_home

Member
You would follow the same logic. To get the last day of the current month one year previous.
first day of the next month from previous year would be
( month = today + 1 month
day = 01
year = year of today - 1 )

Then you subtract 1 day.
 

UncleNel

New Member
I found a month-end function (someone else developed the code - no credit to me) that I have used before and maybe you can adapt it to your requirements.

Function MonthEnd Returns Date ( input inDate As Date):
Return (Date(Month(inDate),28,Year(inDate)) + 4) -
Day(Date(Month(inDate),28,Year(inDate)) + 4).
End.

message string(MonthEnd(today),"99-99-99") skip /*current month*/
string(MonthEnd(today - 4),"99-99-99") skip /*last month*/
string(MonthEnd(today - 365),"99-99-99") skip /*last year*/
string(MonthEnd(02/01/2012),"99-99-99") /*leap year*/
view-as alert-box.
.
 

TomBascom

Curmudgeon
Code:
display
  today skip
  date( month( today ), 1, year( today )) - 1 skip
  date( abs( month( today ) - 11 modulo 12 ), 1, year( today ) - 1 ) - 1 skip
.
 

TomBascom

Curmudgeon
Test first, then post ;)

Code:
display
  d skip
  date( month( d ), 1, year( d )) - 1 skip
  date(( month( d ) + 13 ) modulo 12, 1, year( d ) - 1 ) - 1 when month( d ) <> 12
  date( 12, 31, year( d ) - 1 ) when month( d ) = 12
.
 
Top