[SalesForce] How to convert string into Date format

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');

Best Answer

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:

  • The newInstance method takes Integers as parameters
  • format() will format the date in the current user's locale

Read more on Date Methods