How to convert string to Date in apex?
What is wrong with this format while am upserting the date in an object?
Route__c r =new Route_c(); r.Plan_Date__c = date.parse(strDate); upsert r;
In the debug log, I get the error as |FATAL_ERROR|System.TypeException: Invalid date: Test123
Here Test123 is the different text to be inserted which accepts as Date and throws an error.
you'll be much happier if all incoming dates are in yyyy-mm-dd format to avoid locale-specific issues
This error is coming as system is not able to understand
Test123while parsing into date.
The format of the String depends on the local date format, like
mm/dd/yyyy. If the parameter is not of this format,
date.parsewill throw error.
r.Plan_Date__c = date.parse('12/27/2015');
You can also use
date.valueOf(strDate)to parse string of format
yyyy-MM-dd HH:mm:ssin the local time zone.
Please use this link to read about more date properties.