0

I have a custom Date field.

I want to display this on a visualforce page.

I tried to display it like this but the date is not showing:

<tr>
    <td>
        <apex:outputField value=" {!myobject.testDate__c}"/>
    </td>
</tr>

or like this

<tr>
    <td>
        {!myobject.testDate__c} 
    </td>
</tr>

or like this

<tr>
    <td>
        <apex:outputtext value="{0, date, short}">
            <apex:param value="{!myobject.testDate__c}"></apex:param>
        </apex:outputtext>
    </td>
</tr>

but none of the above would display me the date.

I can confirm that I do see the testDate__c object display the date in my page layout.

Can someone please help me as to why I don't see the date display? Thanks

2
  • Looks like you are doing this correctly. Is myobject set in your controller? Are you able to access other fields from the record? Although, I'm not 100% sure you can use short in the output text option. – JRiffe Sep 25 '17 at 21:02
  • Yeah, I would bet OP doesn't have a setter...OP, if you post your controller, we can verify – Brian Mansfield Sep 25 '17 at 21:13
0

There shouldn't be any issues using outputField. If you can't see the value I can only think of two reasons:

  • 1 - The value is not set on your object;
  • 2 - You don't have permission to view the field;

Also, there's another syntax that you can use to display the date:

<apex:outputText value="{0, date,dd MMM yyyy}">
    <apex:param value="{!obj.DateField__c}"/>
</apex:outputText>
2
  • 1 - I can confirm that the testDate__c field is containing values and is displayed correctly on may page layout. 2 - can you pleat let me know what permission I might be missing? – CB4 Sep 26 '17 at 1:51
  • thank you. it is permission to view is missing for the field. – CB4 Sep 26 '17 at 15:25
0

when using outputField - it should display as a date if you have a value - it will be blank if null. Otherwise,

<apex:outputText value="{0, DATE, MM'/'dd'/'yyyy}">
    <apex:param value="{!MyObject__c.Date_Field__c}" />
</apex:outputText>

with the above you can pass a date from the back end or a date from the field - so if you create for example:

  public Date today = System.today();

in your controller - you can display that date using the above like so:

<apex:outputText value="{0, DATE, MM'/'dd'/'yyyy}">
    <apex:param value="{!today}" />
</apex:outputText>

OR format as this:

 <apex:outputText value="{0, DATE, yyyy'-'MM'-'dd}">
    <apex:param value="{!today}" />
 </apex:outputText>

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.