- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 05:29 AM
Hi,
I want to split Date & time from below value and pass it into a date time filed in the format yyyy-MM-dd HH:mm:ss.
2022-03-24T23:59:59.000+00:00
Please help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 05:50 AM
Hi,
the value you are having is in ISO format
use this to get only date/time
Script:
var iso = '2022-03-24T23:59:59.000+00:00';
var date = iso.split('T')[0];
var time = iso.split('T')[1].split('.')[0];
var dateTime = date + ' ' + time;
gs.info(dateTime);
Output:
[0:00:00.062] Script completed in scope global: script
Script execution history and recovery available here
*** Script: 2022-03-24 23:59:59
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 06:34 AM
I've just checked this, and GlideDateTime does actually support this format:
var gDate = new GlideDateTime('2022-03-24T23:59:59.000+00:00');
gs.print(gDate);
*** Script: 2022-03-24 00:00:00
More info can be found here, so there shouldn't be any need to do splits etc,
Many thanks,
Kind regards
Director of Globalization Deployment, Internationalization
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 07:54 AM
Hi All,
I am confused with the replies as if which 1 I should follow:
My main motive it to fetch the value from the field as follows. Expires field is a string type field.
After fetching, I need to pass it into a field as follows which is a Date/Time field.
So, I wanted to remove the T from the Expires value and also remove that 000+00:00, so that I can update the Valid To with Date/Time only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 08:20 AM
You should follow the post from Alex
You should take the "expires" value, pass it into a new GlideDateTime object as a parameter and pass the result of that variable into your Valid to field.
Something like:
var gdt = new GlideDateTime(expiresValue);
record.setValue('valid_to', gdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 10:02 PM
Did you face any challenge in the script shared by me or Mike?
what is not working?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader