0
apex:variable var="Expiry" value="{!if((TEXT(object.Executed_Expiry_Date__c)!=null && TEXT(object.Executed_Expiry_Date__c)!=''),object.Executed_Expiry_Date__c,
        object.Expiry__c)}" 

             {!IF((object.Expiry__c== true),'Exp. Date: '&TEXT(Expiry), '')}

the code runs fine. but displays date in a yyyy/mm/dd format. How can I change the format to dd/mm/yyyy in Vf ? Executed_Expiry_Date__c and Expiry__c are date fields.

1

You can format like below

<apex:outputText value="{0,date,dd/MM/yyyy}" >
    <apex:param value="{!object.Executed_Expiry_Date__c }" />
</apex:outputText>

Updates 2

<apex:variable var="Expiry" value="{!if((TEXT(object.Executed_Expiry_Date__c)!=null && TEXT(object.Executed_Expiry_Date__c)!=''),object.Executed_Expiry_Date__c,
    object.Expiry__c)}" />
<tr>
  <td>
    <apex:outputPanel rendered="{!object.Expiry__c}">
        'Exp. Date: '
        <apex:outputText value="{0,date,dd/MM/yyyy}" >
            <apex:param value="{!Expiry}" />
        </apex:outputText>
    </apex:outputPanel>
  </td>
</tr>
  • Yes that I can but I am not displaying {!object.Executed_Expiry_Date__c } directly I am taking that in a variable first – Afroz Kazi Nov 23 '16 at 12:01
  • @AfrozKazi check my updates – Ratan Paul Nov 23 '16 at 12:06
  • Yes but the problem is that i need to check one more condition {!IF((object.Expiry__c== true),'Exp. Date: '&TEXT(Expiry), '')} this is where the value from variable is displayed on the screen. So the code has to work like this if expiry__c is true then check if executed expiry is having any value in it if it does print the same else print expiry date and for expiry__c false print nothing. – Afroz Kazi Nov 23 '16 at 12:13
  • 1
    @AfrozKazi check my updates 2 – Ratan Paul Nov 23 '16 at 12:20
0

When using a var you can access its data in the following manner:

<apex:variable var="Expiry" value="{!if((TEXT(object.Executed_Expiry_Date__c)!=null && TEXT(object.Executed_Expiry_Date__c)!=''),object.Executed_Expiry_Date__c, object.Expiry__c)}"/>

<apex:outputText value="{0,date,dd/MM/yyyy}" >
    <apex:param value="{!Expiry}" />
</apex:outputText> 

This will allow you to modify the var conditions but still receive the same output you are looking for.

Have a look at the JavaDocs for SimpleDateFormat for the various date formats.

  • but before printing the value i need to check one more thing {!IF((object.Expiry__c== true),'Exp. Date: '&TEXT(Expiry), '')} – Afroz Kazi Nov 23 '16 at 12:17
  • Is your question based on formatting the output or are you looking for extra answers? If so I would raise a new question but for now I believe your question to formatting is answered. – TSmith Nov 23 '16 at 12:25

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.