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
Shiva Mali 13Shiva Mali 13 

Convert the string to date

I have string 2017-12-22T09:21:00Z.. 

Need to convert this to Date and compare with Variable(Date datatype);

written the code like this. 

Date tempdate;

if(date.valueof(2017-12-22T09:21:00Z)> tempdate) {

tempdate = date.valueof(2017-12-22T09:21:00Z);
system.debug('I am In IF now');
}

Code is getting compiled.. but if part is not returning true.. hence not able to print I am In IF now..
Please advice how to proceed.. 

Thanks in advance

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Shiva,
  • The format of the String depends on the local date format, like 'mm/dd/yyyy'. If the parameter is not of this format, date.parse will throw an error.
  • Eg: r.Plan_Date__c = date.parse('12/27/2015');
  • You can also use date.valueOf(strDate) to parse string of format “yyyy-MM-dd HH:mm:ss” in the local time zone.
Please refer the below link for reference. hope it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar