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
j-dj-d 

Unable to pass date as a param in a vf page

I'm unable to pass a date param in a vf page ... am I doing something wrong or is this a bug? Below is an example of the page and controller. It works when passing it into a string field but not when going from date to date. 

 

<apex:page controller="testPage2Con">
    <apex:form id="mainForm">
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:outputText value="{!date1}" label="date1"/>
                <apex:outputText value="{!date2}" label="date2"/>
                <apex:outputText value="{!dateString}" label="dateString"/>
                <apex:commandButton value="Set TRX Date" reRender="mainForm" action="{!setDateAction}">
                    <apex:param name="setDate" value="{!date2}" assignTo="{!date1}" />
                    <apex:param name="setDescription" value="{!TEXT(date2)}" assignTo="{!dateString}" />
                </apex:commandButton>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public class testPage2Con {

    public Date date1{get{return date1;}set;}    
    public String dateString{get{return dateString;}set;}
    
    public Date date2;
    
    public Date getDate2(){
        if(date2 == null)
            date2 = system.today();
        return date2;
    }

    public void setDateAction(){
    
    }

}

 

Best Answer chosen by Admin (Salesforce Developers) 
JitendraJitendra

Hi,

While passing the date, pass month, day and year separately or if you dircetly pass the string equivalent then you will need to extract the day, month and year.

And at the destination controller, again create the object of Date by passing day, month and year.

 

Please see below documentation : 

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

All Answers

JitendraJitendra

Hi,

While passing the date, pass month, day and year separately or if you dircetly pass the string equivalent then you will need to extract the day, month and year.

And at the destination controller, again create the object of Date by passing day, month and year.

 

Please see below documentation : 

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

This was selected as the best answer
Dipa87Dipa87

Make Date 1 and date 2  string variables.

Pass the dates as string to apex and then convert it.