If you need to find the last day of the month, you can do complicated DateTime gymnastics or you can use the following method.
Say you want to find the last day of February 2021. Do the following:
Integer month = 2;
Integer day = null;
Integer year = 2021;
// Create a new DateTime object for ...