- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 08:20 AM
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!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 08:52 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 11:07 AM
Anna,
Wow!! I do not know why you want achieve this in 50 lines, when you can achieve this in 4 lines!!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 11:09 AM
I agree with Abhinay on this one, Anna. Please mark his answer as correct so that others can use the most efficient method possible if they have a similar question/issue in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 11:28 AM
Okay Chuck,
but maybe you know what causes the change of the initial date from my mail?
The solution proposed is keeping to change the date and time of converted string, i.e. for the date which i get from my email (in my example email it isThursday, July 14, 2016 11:00:43 PM)
the resulting DATE/TIME record is - 2016-07-15 08:00:43

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 11:30 AM
When you do getDisplayValue() it will convert that to date/time in user timeZone(). If you want the exact date/time in the email. go with chuck's solution by parsing the actual values

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 11:30 AM
It is applying the timezone.
When you use
gdt.getDisplayValue();
the timezone is applied. If you use
gdt.getValue();
no timezone. It's just a matter of which one you want to store.
GlideDateTime - ServiceNow Wiki