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
karthik karthikkarthik karthik 

how to convert string to date

Hi,

i want to convert string to date format, when i try to solve this i got the following error " System.TypeException: Invalid date/time: 9/25/2014 7:21:49 PM"

my code is like below

           DateTime dt = DateTime.valueof('9/25/2014 7:21:49 PM');      
           string strdate = dt.format('mm/dd/yyyy');         
           tf.Resolve_Schedule_date__c = date.valueof(strdate);

if anyone know pls me.........
Thanks in Advance.
         
Mani RenusMani Renus
Try this

DateTime dt = DateTime.parse('27/10/2014 10:00 AM');


Shashikant SharmaShashikant Sharma
See these posts having solution for the same 

http://salesforce.stackexchange.com/questions/36376/how-to-convert-date-string-to-datetime-type-without-gmt
http://stackoverflow.com/questions/18039145/string-to-datetime-conversion-in-salesforce

You just need to convert your string in the format that is acceptable by any of the Date method to create new date instance.

See Date methods : 

http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_date.htm