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
RajashriRajashri 

Date comparision error

I have a fied Project_Create_Date as date field.

 

I an trying to write below code

 

 

if(Project_Create_Date__c)>'1/1/2012')

{

}

 

but it's giving me below error.

 

Comparison arguments must be compatible types: Date, String at line 103 column 19

 

Can anyone help me to resolve it?

 

 

 

zachbarkleyzachbarkley

if(MyObject__c.Project_Create_Date__c>Date.ValueOf('01/01/2012'))

sfdcfoxsfdcfox
You have to convert the string to a date.

Either use Date.valueOf(String), Date.parse(String), or Date.newInstance(Year, Month, Day) to construct a new date.