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
NishaCNishaC 

Getting Error: Invalid Integer.. when converting string to integer

i have used this method for converting string date to integer date

 

String[] myDateOnly = dateFrom.split(' ');
String[] strDate = myDateOnly[0].split('/');
Integer myIntDate = integer.valueOf(strDate[0]);  //getting error: invalid Integer
Integer myIntMonth = integer.valueOf(strDate[1]);
Integer myIntYear = integer.valueOf(strDate[2]);
Date d = Date.newInstance(myIntYear, myIntMonth, myIntDate);

 

Please help me in this

Best Answer chosen by Admin (Salesforce Developers) 
Tejpal KumawatTejpal Kumawat

Hi NishaC

 

Use this Snippt given below:

 

 

String strDate = '12/12/2009';
String[] myDateArray = strDate.split('/');
Integer myIntDate = integer.valueOf(myDateArray[0]);
Integer myIntMonth = integer.valueOf(myDateArray[1]);
Integer myIntYear = integer.valueOf(myDateArray[2]);
Date d = Date.newInstance(myIntYear, myIntMonth, myIntDate);
System.debug('***'+d);

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Thanks & Regards

 

Tej Pal Kumawat

(Certified Developer) | http://salesforce-evershine-knowledge.blogspot.in/

All Answers

AmitSahuAmitSahu
Replied on the other post .. use split(",")
mrajmraj

Please use system debug to see the value of  myDateOnly and strDate field. This will help you to check if you are getting the value as expected after the split.

 

 

 

 

 

NishaCNishaC

debugs:

 

======strDate==========(03, 09, 2012)
=======myIntDate==========3
===myIntMonth==========9
====myIntYear==========2012

actually i am selecting value from calendar....at starting it is blank value and after selecting any value and clicking on GO button 

it again displays blank value

Tejpal KumawatTejpal Kumawat

Hi NishaC

 

Use this Snippt given below:

 

 

String strDate = '12/12/2009';
String[] myDateArray = strDate.split('/');
Integer myIntDate = integer.valueOf(myDateArray[0]);
Integer myIntMonth = integer.valueOf(myDateArray[1]);
Integer myIntYear = integer.valueOf(myDateArray[2]);
Date d = Date.newInstance(myIntYear, myIntMonth, myIntDate);
System.debug('***'+d);

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Thanks & Regards

 

Tej Pal Kumawat

(Certified Developer) | http://salesforce-evershine-knowledge.blogspot.in/

This was selected as the best answer