Ho to Parse STRING to Date/Time field?

hyperjam
Giga Contributor

Hello, i have an inbound email action to create a new records from emails.

The email body_test contains string date, presented in such way, for example - Thursday, July 14, 2016 11:00:43 PM

I'm extracting that date, and i need it to be inserted in the DATE/Time field [u_date] (so for example -   2016-07-14 23:00:43)

Do you have suggestion on how to do that?

Any input will be welcomed, because i'm lost with that

Thank you!

1 ACCEPTED SOLUTION

Oh wow, that is a lot of coding. If I am not wrong, this can be achieved in 4 lines


var sec=Date.parse("Thursday, July 14, 2016 11:00:43 PM");


var gdt = new GlideDateTime();


gdt.setNumericValue(sec);


gdt.getDisplayValue(); //this will give you the date in your format


View solution in original post

25 REPLIES 25

Tried with both but with getValue() - also not the same


example email it isThursday, July 14, 2016 11:00:43 PM)


the resulting DATE/TIME record is - 2016-07-15 06:00:43



Chuck, when i tried your solution, can you please tell me what is wrong with variable assignment



  1. var str = 'July 14, 2016 11:00:43 PM'; //works
  2. \\   in my case i put
  3. var testDate = email.body_text.substring(email.body_text.indexOf('follows:')+8, email.body_text.indexOf(' PM')+3).trim();
  4. var str = testDate; // result -   the field in the table is empty.
  5. \\or

                            var testDate = email.body_text.substring(email.body_text.indexOf('follows:')+8, email.body_text.indexOf(' PM')+3).trim();


                              var str = str + testDate;// result -   the field in the table is empty.


                                           


Hello Chuck,

We have slimier requirement like,

I need to sent an email body like ..

 

Date : 22/01/2020

Time : 12:02:31

 

when I am sending like this - i need to merge date and time both need to set it in one custom table column like date and time .

 

how to merge in inbound action both of email body , please help me with same .

@Chuck Tomasi 

@Abhinay Erra 

Are you talking about processing the inbound mail or outbound? your other message made it sound like inbound. Just wanted to be sure.

See my response to process inbound email on your other message here:

Merge Email Date and time body in inbound email action.

Which time zone are you in?


CET GMT+1