You need to sign in to do that
Don't have an account?
John_SFDC
How to convert the String to Date time.
I have the String '11/12/15 10:42' to Date time format.
I have Date_take__C field on Case object.I am Using EMail to case functionality .where i am getting the Case Description from the email body,from the email body i have captured the '11/12/15 10:42' in to string vairable.But now am not able to assign to the Date_take__C case field.
Thanks in advance.
I have Date_take__C field on Case object.I am Using EMail to case functionality .where i am getting the Case Description from the email body,from the email body i have captured the '11/12/15 10:42' in to string vairable.But now am not able to assign to the Date_take__C case field.
Thanks in advance.
Use the below code to convert the string to datet ime.
The console output is
Let me know if you know need any help regarding this,
Thanks,
Vijay
Let me know if you need any help regading this.
Thanks,
Vijay
This code may help you.
String strTest = '11/12/15 10:42';
String[] arrTest = strTest.split('/');
DateTime d = DateTime.newInstance(Integer.valueOf(arrTest[2].substring(0,2)),Integer.valueOf(arrTest[1]),Integer.valueOf(arrTest[0]));
let me know, if it helps you or need any help :)
shiva.sfdc.backup@gmail.com
11
Try this:
String[] strDateArray = strDateTime.split(' ')[0].split('/');
Date dteDate = Date.newInstance(integer.valueOf('20' + strDateArray[2]),
integer.valueOf(strDateArray[1]),
integer.valueOf(strDateArray[0]));
It assumes the data string format is always 'dd/mm/yy hh:mm'.
The year format is only 2 characters in length, so it assumes it is the year 2015 when the date is created.
I would recommend including some string validation to ensure the supplied string is in the appropriate format and raise custom exceptions if it is not with a description of the issue to aid debugging later if the date string supplied does not meet the expected format.
Hope that helps,
Richard Jimenez