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
moverdorfmoverdorf 

Hopefully an easy one here guys....

I am trying to compare an apex variable defined as a DATE to my p.MVH_Month__c date value. (I only want to render the outputText on a control break on the data.)

 

<apex:variable var="LastMonth" value="{Date.parse('1990-01-01')}" />    
 <apex:repeat var="p" value="{!port}">
        <apex:outputText rendered="{!if(LastMonth != p.MVH_Month__c,true,false)}">

        .

        .

        .

The code won't compile it says "incorrect parameter type for operator <>. Expected TEXT received DATE.

 

If I change the code to this: <apex:outputText rendered="{!if(LastMonth != null,true,false)}"> it compiles so it looks like even though I am defining the <apex:variable LastMonth as a Date, the compiler is treating it like it is a String.

 

Thanks for any advice on this.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

I probably spotted the issue

 

<apex:variable var="LastMonth" value="{Date.parse('1990-01-01')}" />    

 I dont think you can initiate a date like this ! to call a function you need have a merge notation {! } , and your code is missing that one and the variable LastMonth is storing the whole thing as string.

 

Addtionally you cannot init a date in a VF page like this, even if you correct the syntax, you wil get an error

 

 

All Answers

amarcuteamarcute

Comparision between two dates as shown bellow Saves without any compilation issues & works fine

 

<apex:page standardController="account">
<apex:outputText rendered="{!if((account.LastModifiedDate = account.CreatedDate), true, false)}">This is what I wanted</apex:outputText> <br/>
Some other Text!
</apex:page>

 

One way of doing it in your case is, instead of declaring the Apex variable in Page move it to Controller. Also, make sure to the variable as Date or Datetime depending upon the field typr you are going to comapre it with. That should work.

 

global with sharing class TestController {

public TestController(ApexPages.StandardController controller) {

}


public Datetime testDate{ get; set; }

public TestController(){
testDate = Date.valueof('1990-01-01');
}
}

 

<apex:page standardController="account" extensions="TestController">
<apex:variable var="LastMonth" value="{Date.valueOf('1990-01-01')}" />
<apex:outputText rendered="{!if((testDate = account.CreatedDate), true, false)}">This is what I wanted</apex:outputText><br/>
Plain Text!
</apex:page>

Avidev9Avidev9

I probably spotted the issue

 

<apex:variable var="LastMonth" value="{Date.parse('1990-01-01')}" />    

 I dont think you can initiate a date like this ! to call a function you need have a merge notation {! } , and your code is missing that one and the variable LastMonth is storing the whole thing as string.

 

Addtionally you cannot init a date in a VF page like this, even if you correct the syntax, you wil get an error

 

 

This was selected as the best answer