A recent tip showed how to calculate the last day of a month. It worked nicely, but unfortunately, only if your date format is dd/mm/yy (UK, I think).
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
This version works anywhere.
Basic idea: Advance the day into the next month, then go back to the first day of the next month -- and one day further.
start_date := @Today;
next_month := @Adjust(start_date; 0; 1; 0; 0; 0; 0);
last_of_month := @Adjust(next_month; 0; 0; -@Day(next_month); 0; 0; 0);
The -@Day(next_month) actually advances to the last day of the previous month, which is really our start month. Think about it...
start date: July 3, 1968
next month: August 3, 1968
Day of next month: 3
August 3 - 2 days is August 1, but August 3 - 3 days is July 31.
This works no matter what month, no matter what year, no matter what day of the month you start on. Since it doesn't use any text conversion, it doesn't rely on any assumptions as to date format.