How do we get the first day of the month and the last day of the month? I am using it on an apex class.

I can get today's date by using

date.today()

but how would I get the first and last day of the month?

0 votes

With respect to your question, you get the first date of the month (I'll use today's month in my example) using the following

`Date firstDayOfMonth = System.today().toStartOfMonth();`

To get the last day of the month, use the following:

`Date lastDayOfMonth = firstDayOfMonth.addDays(Date.daysInMonth(firstDayOfMonth.year(), firstDayOfMonth.month()) - 1);`