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
Von V.Von V. 

Parse Date format

Hi,

We have a text field which has a date of format of d-mmm-yy (22-Jun-16). Unfortunaly, we are having problem converting to Salesforce Date format (mm-dd-yyyy)

Suggestions will be highly appreciated.

Thanks!
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Von V,

please try this code,
 
String dateString = '22-Jun-16';
List<String> dateSplit = dateString.split('-');
Integer dd = Integer.valueOf(dateSplit.get(0));
String mmString = dateSplit.get(1);
Integer mm;
if(mmString.toUpperCase() == 'JAN')
	mm = 1;
else if(mmString.toUpperCase() == 'FEB')
	mm = 2;
else if(mmString.toUpperCase() == 'MAR')
	mm = 3;
else if(mmString.toUpperCase() == 'APR')
	mm = 4;
else if(mmString.toUpperCase() == 'MAY')
	mm = 5;
else if(mmString.toUpperCase() == 'JUN')
	mm = 6;
else if(mmString.toUpperCase() == 'JUL')
	mm = 7;
else if(mmString.toUpperCase() == 'AUG')
	mm = 8;
else if(mmString.toUpperCase() == 'SEP')
	mm = 9;
else if(mmString.toUpperCase() == 'OCT')
	mm = 10;
else if(mmString.toUpperCase() == 'NOV')
	mm = 11;
else if(mmString.toUpperCase() == 'DEC')
	mm = 12;
Date finalDate = Date.newInstance(Integer.valueOf(dateSplit.get(2)), mm, dd);

Thanks
Prosenjit
Von V.Von V.
Hi Presenjit,

Thanks for your provided suggestion, I was able to save the code withouth error but when I try to peform an update to the record.
I received Erro "invalid date: Mon Jun 22 00:00:00 GMT 16".

I try to debug.

Thanks,
Von
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Von,

May be thats because of some existing code.

Thanks,
Prosenjit
Von V.Von V.
Hi Prosenjit,

Your provided code works properly. Thanks!