+ Start a Discussion
Santhosh AloorSanthosh Aloor 

invalid date

Hi ,

 

Iam trying to convert String (Mon Oct 14 00:00:00 GMT 2013) to Date

 

String sDate=  'Mon Oct 14 00:00:00 GMT 2013';

Date startDate = date.parse(sDate);
 system.debug('**********eDate*********'+startDate);

 

iam getting the below error:

 

07:56:48.075 (75842000)|SYSTEM_METHOD_ENTRY|[76]|Date.parse(String)
07:56:48.076 (76008000)|EXCEPTION_THROWN|[76]|System.TypeException: Invalid date: Mon Oct 14 00:00:00 GMT 2013
07:56:48.076 (76189000)|SYSTEM_METHOD_EXIT|[76]|Date.parse(String)
07:56:48.076 (76269000)|FATAL_ERROR|System.TypeException: Invalid date: Mon Oct 14 00:00:00 GMT 2013

Class.workingSFDCHrsController.loadOpps: line 76, column 1
07:56:48.076 (76279000)|CODE_UNIT_FINISHED|VFRemote: workingSFDCHrsController invoke(loadOpps)
07:56:48.076 (76285000)|EXECUTION_FINISHED

 

 

Please help me.

 

Thanks advance,

Santhosh.A

prakash_sfdcprakash_sfdc

Map <String, Integer> monthNames = new Map <String, Integer> {'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12};

List stringParts = 'Wed Aug 07 04:30:00 GMT 2013'.split(' '); //Splitting on blank space

List timeParts = stringParts[3].split(':');  //Splitting on :

DateTime yourDateVariable = DateTime.newInstanceGmt(Integer.valueOf(stringParts[5]), monthNames.get(stringParts[1]), Integer.valueOf(stringParts[2]), Integer.valueOf(timeParts[0]), Integer.valueOf(timeParts[1]), Integer.valueOf(timeParts[2]));

 

http://salesforce.stackexchange.com/questions/15098/how-to-convert-a-text-to-datetime