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
Ashu sharma 38Ashu sharma 38 

how to show date field in vf page

Hello!!!!!!!

in the beow code i am displaying date but i want to dispaly as per the standard look as salesfroce date displaying.
<apex:page controller="UserRegistrationForm" docType="html-5.0">
    
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!SaveUserRegistrationForm}" value="Sumbit"/>
                <apex:commandButton action="{!cancelMe}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                Name:<apex:inputText value="{!name}"/>
                LastName:<apex:inputText value="{!lastName}"/>
                User Name:<apex:inputText value="{!userName}"/>
                Password:<apex:inputSecret value="{!password}"/>
                Date:<apex:input type="date" value="{!dateOfBirth}"/>
                
                
                
            </apex:pageBlockSection>
            
        </apex:pageBlock>
        
        
    </apex:form>
</apex:page>
SandhyaSandhya (Salesforce Developers) 
Hi,

You can try using <apex:inputField value="{!dateOfBirth}"

Best Regards,
Sandhya
Meenu MathewMeenu Mathew
Hi Nitish,

Use  apex:InputText  in your Visualforce Page.

Then please change the date formatt in controller
myDate (this is ur date feild)
String dayString = myDate.format();

Thanks

 
Ashu sharma 38Ashu sharma 38
Hi Sandhya...

Thank you for you answer but its not working,i ma geetibng an error on this....
"Could not resolve the entity from <apex:inputField> value binding '{!dateOfBirth}'.  <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable."
Ashu sharma 38Ashu sharma 38
Hi Meenu.

thank you for your answer,

i have  an doubt....should i change the filed datatype of "date"?? bcoz i have declared date as datatype.
when i am using you code code getting error....
Meenu MathewMeenu Mathew
Hi,

Can you please share the error.
Ashu sharma 38Ashu sharma 38
Hi..
I am taking the date type datatype for Date....
and you mention that take string type...
Meenu MathewMeenu Mathew
Hi,
Use dayString instead of dateOfBirth in your visualforce code.
Also make it apex:InputText.
Ashu sharma 38Ashu sharma 38
Hi...

Illegal assignment from Date to String
error is coming......
Ashu sharma 38Ashu sharma 38
Hello...
I am done but not come same as standard date field format....
its seems like as same as HTMl format which come earlire...no change.....


 
Meenu MathewMeenu Mathew
Hi,
Make sure you are using apex:InputText instead of apex:input.

Date:<apex:InputText value="{!dayString}"/>
Ashu sharma 38Ashu sharma 38
Hello....

Below code....

          Date: <apex:panelGroup styleClass="col02 requiredInput" layout="block">
                        <apex:panelGroup styleClass="requiredBlock" layout="block"></apex:panelGroup>
                        <apex:inputText value="{!dayString}"/>
                    </apex:panelGroup>
is it????

public class UserRegistrationForm {
    
    public string name       {set;get;}
    public string lastName   {set;get;}
    public string userName   {set;get;}
    public string password   {set;get;}
    public date   dayString   {set;get;}
    public integer count ;
    public list<user2__c> UBS;
    public void SaveUserRegistrationForm(){
        user2__c UC=new user2__c();
        UBS=new list<user2__c>();
        UC.name=name;
        UC.last_Name__c=lastName;
        UC.user_name__c=userName;
        UC.Password__c=password;
        UC.Date_of_Birth__c=dayString.format();
Meenu MathewMeenu Mathew
In your code, make this change
public string dayString   {set;get;}
Ashu sharma 38Ashu sharma 38
Now gettingb on error...
Method does not exist or incorrect signature: void format() from the type String