You need to sign in to do that
Don't have an account?
Shiva 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
- 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.- https://developer.salesforce.com/forums/?id=906F000000096TdIAI
- https://salesforce.stackexchange.com/questions/105377/how-to-convert-string-to-date-in-apex
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