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
karthic sankar 9karthic sankar 9 

how to covert string to date

Hi Experts,

Please guide me on how to covert string to date.

I have string in this format 01-01-2020
I need this to be date format 01-01-2020

Reagrds
Karthic 
AbhishekAbhishek (Salesforce Developers) 
Hi,


Sample Code:

String todate = '12/27/2013';  
Date dt = Date.parse( todate );  
system.debug(' Parsed Date is ' + dt );  


User-added image


For further reference, you can check the below blog too,

https://medium.com/@devendargona/how-to-convert-string-to-date-in-apex-9d273a1f61c8


I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
karthic sankar 9karthic sankar 9
Hi Abishek,

Thanks for your reply.
 
but, I have sting in this format  01-01-2020.
Date dt = Date.parse( todate );  // this doesnt work with - format, can u pls help.

Regards
Karthic Sankar V P

 
AbhishekAbhishek (Salesforce Developers) 
There are some limitations to that too.

Check the blog I have mentioned in the above. 
karthic sankar 9karthic sankar 9
Thanks for your reply. Mine is API version 33.0 it seems, it returns me with timeStamp. How to remove the timeStamp can u pls assit.

15:23:53:014 USER_DEBUG [19]|DEBUG|Sankar2015-07-27 00:00:00
AbhishekAbhishek (Salesforce Developers) 
Sankar I haven't tried that scenario and I don't think it is possible too. 

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
 
karthic sankar 9karthic sankar 9
Thank you Abishek. I am gone then. Great efforts from your side. if you are free, you can let me know this too.

https://developer.salesforce.com/forums/ForumsMain?id=9062I000000QzvbQAC