You need to sign in to do that
Don't have an account?

How to convert string to Date format
Hi,
I have a string, '11/20/2010 12:00:00 PM' and i would like to set this into Date format (NOT DateTime) since i want pass this value into one of my field of type date.
Here my function:
private Date setStringToDateFormat(String myDate)
{
String[] myDateOnly = myDate.split(' ');
String myDateString = myDateOnly.get(0);
String myHourString = myDateOnly.get(1);
DateTime d = DateTime.valueOf(myDateString + ' ' + myHourString);
return Date.valueOf(d);
}
However, everytime I run this, i received an error Invalid Date/Time.
Could someone help???
You can use following method
-Suresh
use
works in some locales
Thanks. It works.
Try this:
Regards,
Abhiraj
use this :-
String date = '2024-06-01';
Date newDate = Date.valueOf(date);
Regards,
Ganesh