I have 3strings. I want to convert it into date
How to achieve this ?
string a='20';
string b='4';
string c='1993';
String dt = DateTime.newInstance(a,b,c).format('d-MM-YYYY');
Alternatively, the way you were headed it's something like this:
String dt = Date.newInstance(Integer.valueOf(c),Integer.valueOf(b),Integer.valueOf(a)).format();
Keep in mind:
newInstance
method takes Integers as parametersformat()
will format the date in the current user's locale Read more on Date Methods
string year = '1993';
string month = '4';
string day = '20';
string stringDate = year + '-' + month
+ '-' + day ;
Date myDate = date.valueOf(stringDate);
system.debug('mapPeriodDay>>>'+myDate);
Made this change in your existing code
DateTime.newInstance(integer.valueof(c),integer.valueof(b),integer.valueof(a)).format('dd-MM-YYYY');