[SalesForce] System.TypeException: Invalid date:05/05/2013

i just executed these lines in anonymous block and got this exception. Any suggestions?

Date dt;
dt = Date.valueOf('05/05/2013');
System.debug(dt);

System.TypeException: Invalid date: 05/05/2013

Best Answer

I useually try and keep dates in the yyyy-MM-dd format as this is more widely accepted in development.

Your code becomes:

Date dt;
dt = Date.valueOf('2013-05-05');
System.debug(dt);

and runs successfully.

Related Topic