One technique I have used to get the desired result is as follows:
Call TimeYmdHms() to get the current date & time.
Parse out the year and month portions, then either increment the month by one, or, in the case of December, set the month to one and increment the year, and set the day of month to one. Build a new YmdHms string with the new year, month & day values, leaving the "Hms" portion as zeros.
Call TimeSubtract() to subtract one day from the newly calculated date & time string.
The result is a YmdHms formatted string containing the date for the last date of the current month.