I would recommend finding the first day of next month, and subtracting one day from that. (You don't want to rewrite logic for leap year) For maintainability, I'm splitting it up into Params assuming you're doing this in a property-set:
With all date-time manipulation like this, you have to be careful about timezones. Because pega uses GMT in many of these calculations, odd things might happen if you are ahead or behind GMT. getCurrentDateStamp might be good for testing, but I think you might want to use something that takes the user's time zone into account. I would test carefully around flipping over from one day to the next, one month to the next, and one year to the next.