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
sp13sp13 

Displaying Dates in pageBlockTable

How to display selected startDate to endDate in a pageBlockTable?
For example, I selected January 1 as startdate and January 5 as enddate. How can I display each date in different rows?

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Here is required solutions, Simply you need to create two field in Account. 

 

<apex:page controller="dateInPBTbaleController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="Start Date" />
                     <apex:inputField value="{!account.FromDate__c}"/>
                 </apex:pageBlockSectionItem> 
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="End Date" />
                     <apex:inputField value="{!account.Todate__c}"/>
                 </apex:pageBlockSectionItem> 
                 <apex:commandButton value="Disply" action="{!displaingTable}" reRender="tableId"/>  
            </apex:pageBlockSection> 
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!listOfDates}" var="date" id="tableId">
                    <apex:column value="{!date}" headerValue="Start Date"/>
                            
                        
                </apex:pageBlockTable>
            </apex:pageBlockSection>  
        </apex:pageBlock>
    </apex:form>
  
</apex:page>

 My controller 

public with sharing class dateInPBTbaleController {
    public Account account{get;set;}
    public List<String> listOfDates{get;set;} 
    
    public dateInPBTbaleController() {
        listOfDates = new List<String>();
        account = new Account();
    }
    
    public PageRefeRence displaingTable(){
        listOfDates.clear();
        String startDate = String.ValueOf(account.FromDate__c);
        String endDate = String.ValueOf(account.Todate__c);
        listOfDates.add(startDate); 
        listOfDates.add(endDate);
        return null;  
    }
   
}

 

All Answers

asish1989asish1989

Here is required solutions, Simply you need to create two field in Account. 

 

<apex:page controller="dateInPBTbaleController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="Start Date" />
                     <apex:inputField value="{!account.FromDate__c}"/>
                 </apex:pageBlockSectionItem> 
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="End Date" />
                     <apex:inputField value="{!account.Todate__c}"/>
                 </apex:pageBlockSectionItem> 
                 <apex:commandButton value="Disply" action="{!displaingTable}" reRender="tableId"/>  
            </apex:pageBlockSection> 
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!listOfDates}" var="date" id="tableId">
                    <apex:column value="{!date}" headerValue="Start Date"/>
                            
                        
                </apex:pageBlockTable>
            </apex:pageBlockSection>  
        </apex:pageBlock>
    </apex:form>
  
</apex:page>

 My controller 

public with sharing class dateInPBTbaleController {
    public Account account{get;set;}
    public List<String> listOfDates{get;set;} 
    
    public dateInPBTbaleController() {
        listOfDates = new List<String>();
        account = new Account();
    }
    
    public PageRefeRence displaingTable(){
        listOfDates.clear();
        String startDate = String.ValueOf(account.FromDate__c);
        String endDate = String.ValueOf(account.Todate__c);
        listOfDates.add(startDate); 
        listOfDates.add(endDate);
        return null;  
    }
   
}

 

This was selected as the best answer
sp13sp13

Thanks for the help. However, it's only displaying the startdate and enddate so i fixed it. It's now displaying from startdate TO enddate :)

 

VF Page:

<apex:page controller="SamplePage12CC">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="Start Date" />
                     <apex:inputField value="{!account.startdate__c}"/>
                 </apex:pageBlockSectionItem> 
                 <apex:pageBlockSectionItem >
                     <apex:outputLabel value="End Date" />
                     <apex:inputField value="{!account.enddate__c}"/>
                 </apex:pageBlockSectionItem> 
                 <apex:commandButton value="Display" action="{!display}" reRender="tableId"/> 
            </apex:pageBlockSection> 
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!listOfDates}" var="date" id="tableId">
                    <apex:column headerValue="Dates">
                    <apex:outputText value="{0,date,EEE  MM-dd-yyyy}">
                            <apex:param value="{!date}" />
                    </apex:outputText>
                </apex:column>
                        
                </apex:pageBlockTable>
            </apex:pageBlockSection>  
        </apex:pageBlock>
    </apex:form>
  
</apex:page>

 Controller:

public with sharing class SamplePage12CC {

    public PageReference display() {
        getdisplayingTable();
        return null;
    }
    
    public Sample__c account{get;set;}
    public List<Date> listOfDates{get;set;} 
    Integer totaldays;
    
    public SamplePage12CC() {
        listOfDates = new List<Date>();
        account = new Sample__c();
    }
    
    public Date getdisplayingTable(){
        listOfDates.clear();
        Date startDate = Date.ValueOf(account.startdate__c);
        Date endDate = Date.ValueOf(account.enddate__c);
        totaldays = startDate.daysBetween(endDate);
        Date sd;
        for(integer i=0;i<=totaldays;i++) {
            sd = startDate.addDays(0+i);
            listOfDates.add(sd);
        }
        return sd;  
    }
   
}

 Here is the ouput :)

 

 

 

but now i need to display only weekdays. Saturday and sunday should not be displayed in the table. Any idea how to do this?

 

sp13sp13

i already solved the second question. :) I posted the new problem i encountered. any help? Help in Business Days display