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

SimpleDateFormat - Parse String to DateTime
Hi all,
I am writing a trigger and have a String named 'mappedDueDate' with a value assigned to it, such as:
mappedDueDate = '17/11/2011'
How can I parse this into a DateTime value so that in my trigger I can create a task with the correct Due Date.
e.g.
taskActivityDate = mappedDueDate
At the moment, I get an error message.
I am not a programmer and have received some guidance to understand that I need to parse the string value, but I do not know how.
Any help is much appreciated.
Thanks,
Marco
Its the other way around - the task activity date is a date field rather than a datetime field, so you need to parse a date out of the string.
Change to:
All Answers
You'll need to break the string up into its component parts and create a datetime from it. However, you don't have a time part of the string - I've assumed you want the time as midnight.
Something like:
Hi Bob,
Thanks for your reply.
I have entered that code and now get the error message:
Error: Compile Error: Method does not exist or incorrect signature: DateTime.newInstance(String, String, String, Integer, Integer, Integer) at line 108 column 45
Any advice on how to resolve this please?
Thanks,
Marco
Doh!
Change to:
Thanks again Bob, however you are going to dread my response.
My error now reads:
Error: Compile Error: Illegal assignment from Datetime to Date at line 109 column 17
My code on this line is directly under what you have provided and I have written:
task.ActivityDate = taskActivityDate;
Does the error suggest that the taskActivityDate from your piece of code is a Date rather than Datetime?
Do you have any more suggestions? :)
Thanks for all your help so far...
Marco
Its the other way around - the task activity date is a date field rather than a datetime field, so you need to parse a date out of the string.
Change to:
Thanks again Bob.
I made the change and now get a compile error:
Error: Compile Error: Method does not exist or incorrect signature: Date.newInstance(Integer, Integer, Integer, Integer, Integer, Integer) at line 108 column 41
Should I be declaring anything elsewhere in my trigger for this to work?
That error message doesn't match the code that I posted - mine has three integer parameters. It looks like you've retained the time parsing to. Try using the exact code from my last post.
Thank you very much Bob.
I do apologise, I had left the 0,0,0 part in.
The code now compiles and I have marked the solution as such.
Always impressed with the support of the community here.
Thanks again.
Marco
Glad to hear you got there!