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
Narresh kumarNarresh kumar 

how to get records between two dates in visualforce page


same vf page only User-added image
NagendraNagendra (Salesforce Developers) 
Hi Naresh,

Please find the sample code below and tweak it as per your requirement which should help.
Apex Controller:

public class searchClientVisits{   
    public List<Client_Visit__c> clientVisitList {get;set;}
    public Client_Visit__c clientInfo { get;set;}
    public SearchClientVisits(){  
        clientInfo  = new Client_Visit__c ();
            clientVisitList =new List<Client_Visit__c>();
    }
    public PageReference runSearch(){
            clientVisitList.clear();
        if(clientInfo.Start_Date__c != null & clientInfo.End_Date__c != null ){
            String startDate=String.valueOf(clientInfo.Start_Date__c).left(10);
            String endDate=String.valueOf(clientInfo.End_Date__c).left(10);
            String querystr='SELECT Id,Start_Date__c,End_Date__c,Accounts__c,Clients__c FROM Client_Visit__c WHERE Start_Date__c ='+startDate+' AND End_Date__c='+ endDate;
            clientVisitList = Database.query(querystr);
        }
        return null;
    }
    public PageReference reset(){
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(false);
        return pg;
    }
}

//////////////////////////////////////////////

Visual Force Page:

<apex:page controller="searchClientVisits" id="pg">
    <apex:form id="frm">
        <apex:pageBlock id="pgblk1">
            <apex:pageBlockSection id="pgblksec">
                <apex:inputField value="{!clientInfo.Start_Date__c}" label="Start Date"/>
                <apex:inputField value="{!clientInfo.End_Date__c }" label="End Date"/>
            </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value="Reset" action="{!reset}"/>
            <apex:commandButton value="Search" action="{!runSearch}" reRender="clientList"/>
        </apex:pageBlockButtons>
        </apex:pageBlock>
        <apex:pageBlock id="pgblk">
            <apex:pageBlockTable value="{!clientVisitList}" var="cl" id="clientList">
				<apex:column value="{!cl.Accounts__c}" headerValue="Account Name"/>
				<apex:column value="{!cl.Clients__c}" headerValue="Clients"/>			
				<apex:column value="{!cl.Start_Date__c}" headerValue="Start Date"/>
				<apex:column value="{!cl.End_Date__c}" headerValue="End Date"/>
			</apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
May I also suggest you please check with below links from the community which might help. Hope this helps.

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra.