Hello friends, In this post you will learn, how to get the current month's start and end date using apex code. So let's get started,

Get start and end date of current month in apex

Most of all of us are aware of getting the month start date using toStartofMonth() date function but what about the month end date? I think there is no date function for this. no worries, here i am going to provide a sample code snippet that helps you to do the same.

Sample Code:

 Date startdate = Date.Today().toStartofMonth();
Date enddate = startdate.addDays(Date.daysInMonth(startdate.year(), startdate.month())-1);
System.debug('Start^^'+startdate);
System.debug('End^^'+enddate);

Output:

 

Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.