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
Sandhyarani S PSandhyarani S P 

Import CSV file through VF page.

Error : Invalid date: 19-09-2016

In CSV im giving date like19-09-2016
My code is

detailObj.Date__c = date.ValueOf(csvRecordData[4]);
Still im getting error, i tried pasring also then also im getting the same error.
Nayana KNayana K
19-09-2016 date is in dd-mm-yyyy but to Date.valueOf(String) method needs a string with 'dd-mm-yyyy'. First convert it to that format in apex or in CSV itself you can format it in dd-mm-yyyy format. Then apply Date.valueOf(String).
Harish RamachandruniHarish Ramachandruni

Hi
you can use like this .

 
string [] test = new String[] {'12/27/2009','11/27/2009','10/27/2009'};

date mydate = date.parse(test[0]);

system.debug('test in sales force ' +mydate);

If you have any issue ask me any time .

Let me know it's working or not .




Regards,
Harish.R
 
Sandhyarani S PSandhyarani S P
Hi, I have tried formatting also i got the same error.
Harish RamachandruniHarish Ramachandruni
Hi ,

Show me full code . 



Regards ,
Harish.R.
Harish RamachandruniHarish Ramachandruni
Hi,

Use this code 
 
string [] test = new String[] {'12/27/2009','11/27/2009','10/27/2009'};

date mydate = date.parse(test[0]);

system.debug('test in sales force ' +mydate);

opportunity op = new opportunity ();

op.name = 'test';

op.closedate = mydate ;

op.stageName = 'Closed Won';

insert op ;

system.debug('test in sales force ' +op.id );




It's working properly .



Regards,
Harish.R