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
Saikiran KolliSaikiran Kolli 

Date picker functionality

Hi,

I'm having a VF page with two fields Start Date & End Date.
Using date picker I'm getting the calendar, But the problem is when I open that page automatically Start date , End date values must be populated based on the current month.
For example: If I go to that VF page, as this month is september , start date must be 9/1/2016, End date must be 30/1/2016.
First date and Last date of the current month must be populated. 
Please help me
Best Answer chosen by Saikiran Kolli
Patcs_1Patcs_1
Hi

Try the below code in your apex class.

public date startdate{get;set;}
public date enddate{get;set;}
date highclose = Date.today();
Integer numberDays = date.daysInMonth(highClose.year(), highClose.month());
startdate = Date.newInstance(highClose.year(), highClose.month(), 1);
Enddate =   Date.newInstance(highClose.year(), highClose.month(),numberDays);

Hope this helps.

Thanks

 

All Answers

Patcs_1Patcs_1
Hi

Try the below code in your apex class.

public date startdate{get;set;}
public date enddate{get;set;}
date highclose = Date.today();
Integer numberDays = date.daysInMonth(highClose.year(), highClose.month());
startdate = Date.newInstance(highClose.year(), highClose.month(), 1);
Enddate =   Date.newInstance(highClose.year(), highClose.month(),numberDays);

Hope this helps.

Thanks

 
This was selected as the best answer
Saikiran KolliSaikiran Kolli
Thanks, it works. 
Patcs_1Patcs_1
Hi Saikiran

If my answer fixed the issue, please mark as resolved so that the answers may help others.

Thanks