function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AnumcaAnumca 

Displaying First & Last Dates of a month In VF page

Hi All

 

       I want to display the First & last dates of given month in VF page using Controller

 

forexample: If we given 14/6/2011 date,then it should be display the first date of the month & end date of the month.

 

 Please help me.

 

 

Thanks & Regards

 

Anu

Ritesh AswaneyRitesh Aswaney

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

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm

AnumcaAnumca

Hiii

 

Thanks for the Reply.

 

 

       If u dont mind can u please send me how to call that start string in VF page.

 

 Please help me

 

Thanks& Regards

 

Anu...

Shashikant SharmaShashikant Sharma

Use this

 

Date selectedDate =  Date.today();
Date firstDate = selectedDate.toStartOfMonth();
Date lastDate = firstDate .addDays(date.daysInMonth(selectedDate.year() , selectedDate.month())  - 1);
system.debug(firstDate  + ' **** ' +lastDate );