+ Start a Discussion
jucuzoglujucuzoglu 

Render Component based on Date Comparison

I have two Date fields on an Object that represent Start and End Dates.

 

i would like to Render a component if it falls within the Start and End Dates. The following is an INCORRECT attempt to accomplish this.

 

<apex:outputPanel rendered="{!TODAY()>=Inbox_Assignment__c.StartDate__c && 
!TODAY()<= Inbox_Assignment__c.EndDate__c}">

Does someone know the proper syntax for this?

Best Answer chosen by Admin (Salesforce Developers) 
Baktash H.Baktash H.

try a formula field of type boolean.

write your expression from the visualforce in the formula and it sets the boolean either true or false.

All Answers

Baktash H.Baktash H.

try a formula field of type boolean.

write your expression from the visualforce in the formula and it sets the boolean either true or false.

This was selected as the best answer
jucuzoglujucuzoglu

Can you provide an example (or a URL to an example with a formula field similar to what your describing with the date?)

 

I feel like a big part of my problem is the syntax (not just how I am trying to evaluate the condition) and having an example would be a huge help.

Baktash H.Baktash H.

You make a formula field of type number. (not boolean, that was wrong)

Lets call the field age__c

You insert your fields by clicking on insert field an choosing them.

 

it may look like this:

 

EndDate__c - StartDate__c

And in visualforce you write:

<apex:outputPanel rendered="{!age__c > 0}">

Try this.

Make a few records and watch the number which you get. maybe you need to replace the > with an <.

raseshtcsraseshtcs

Take a boolean variable and use the if condition inside the gette of that variable and then use that Boolean variable to render your component.

Let me know in case you need an example.

 

jucuzoglujucuzoglu

I realized what I think you were saying, Do the Boolean evaluation in the controller and then that variable can be the driver for the rerender.

 

This worked for me (using a boolean).