How to get separate date and time according to UTC format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 01:43 AM
I need date and time in two different variables according to UTC . Any help how can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 01:48 AM
Hello @Akki1
use string.split("T"); for spliting date and time into 2 different Variable.
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:31 AM
If I do var gdt=new GlideDateTime();
gdt.getValue();
I'm not getting this "T" in between I get something like 2023-08-20 15:12:60 . How do we get "T" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:38 AM
Hello @Akki1
Use the below to get date and time seperately
var dateArr =gdt.split(' ');
var time = dateArr[1];//Return time
var date = dateArr[0];//return date
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:39 AM
Try below code
var gdt=new GlideDateTime();
var gdtDate = gdt.getValue();
var date =gdtDate.split(' ');//split with space ,you will get date and time
var date1 = date[0];//this will give you date
var time = date[1];//This will give you time
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact
Thanks,
Manjusha