I am fetching dynamic field values in apex repeat so in these scenario, i am using 1 date field so when i fetch data then it show as a incorrect date format. How is this possible to show date in correct format.

VF Page:-

  <apex:repeat value="{!accessibleFieldsForObjectives}" var="fieldsForObjective" >
  <td> <apex:outputLabel value="{!$Label.PopupCommandLinkLabel}"/> </td>
<apex:repeat value="{!allSchedules}" var="rec">  
    <apex:repeat value="{!accessibleFieldsForObjectives}" var="fieldsForObjective">
         <apex:inputField value="{!rec.sObj[fieldsForObjective]}" style="width: 90px;"/> 
  • Are you referring to the selected date in your inputField? Feb 25, 2015 at 4:17
  • sorry for previous syntax as correct is:- Feb 25, 2015 at 4:29
  • <apex:repeat value="{!rec.children}" var="child"> <tr style="font-size: 11px;align-content: center;"> <apex:repeat value="{!accessibleFieldsForObjectives}" var="fieldsForObjective"> <td>{!child.sObj[fieldsForObjective]}</td> Feb 25, 2015 at 4:30
  • Kindly follow this as i am showing values using these syntex:- <td>{!child.sObj[fieldsForObjective]}</td> . Feb 25, 2015 at 4:31

2 Answers 2


You will need to identify the field type in your back-end and to create a map to keep the date fields. So your apex code should look something like this:

public Map <String, Boolean> fieldIsDate {get; set;}

private void populateListOfFields()
    fieldIsDate = new Map <String, Boolean> ();

    Map<String, Schema.SObjectField> M;
    M = Schema.SObjectType.Account.fields.getMap();
    for (String fieldName : M.keySet())
        if (M.get(fieldName).getDescribe().getType().toString() == Schema.DisplayType.DATE)
            fieldIsDate.put(fieldName, true);

        fieldIsDate.put(fieldName, false);

Then in your visualforce page you'll know if the field name is of type date or not, and depending on that you can render the dates in a specific format:

    <apex:outputText value="{0, date, dd/MM/yyyy}" rendered="{!fieldIsDate[fieldsForObjective] == true}">
        <apex:param value="{!child.sObj[fieldsForObjective]}" name="p0" />
    <apex:outputField value="{!child.sObj[fieldsForObjective]}" rendered="{!fieldIsDate[fieldsForObjective] == false}" />

Your requirement don't seem to be clear. Firstly use outputfield if you want to display time. I assume that it can be datetime field so you have to convert it to date format.

Here is the pseudo code.

DateTime dT = System.now();
Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.