You need to sign in to do that
Don't have an account?
raju.B
Calculate first and last date of the month in a date
Hi,
I need to find a last date and first date of a month of a particular date for controller
Suppose if I select 2011/06/14 from date field ,it need to give first date of 6th month and last date of 6Th month.
Please help me..
Thanks & Regards
Raju.B
the first date, for obvious reasons, will be the first
so
integer monthnumber = 6;
Date todaysdate = Date.today();
Date start = Date.newInstance(todaysdate.year(), monthnumber, 1);
For end use daysInMonth method
integer noOfDays = Date.daysInMonth(todaysdate.year(), monthnumber);
Date end = Date.newInstance( todaysdate.year, monthnumber, noOfDays);
you can also use the toStartOfMonth to get the start date, if you are using a date instance
Thanks & Ragards
Anu...
Use this
You can verify this in system log
Date startDate = System.Date.today().toStartOfMonth();
Date endDate = startDate.addMonths(1).addDays(-1);