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
HsethHseth 

How to use Parse method for Datetimeq

Hi ,

 

I am using the code given beow nad it gives me an exception : "System.TypeException: Invalid date/time: 11/11/2010"

THe code I am using is

 

datetime mydatetime;
mydatetime = datetime.parse('11/11/2010');

 

Cna someone please suggest the solution.

 

Regards

Himanshoo

JimRaeJimRae

According to the documentation the datetime parse method:

Constructs a Datetime from the String datetime in
the local time zone and format.

 

It would require a properly formatted datetime string.

You might be better off using the newinstance method, if you know the format of your inbound string.

Something like this:

 

 

datetime mydatetime;
String inputdate = '11/11/2010';
string[] splitdate =inputdate.split('/');
mydatetime = datetime.newinstance(Integer.valueOf(splitdate[2]),Integer.valueOf(splitdate[0]),Integer.valueOf(splitdate[1]),0,0,0);

 

 

 

Pradeep_NavatarPradeep_Navatar

 In my opinion, there is no parse method in the datetime method.

 

Go through the documentation available on

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_dateformats.htm

 

Hope this helps.