GlideDateTime - get hours, minutes and seconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2018 03:22 PM
Hi all
How Can I extract hour, minute and seconds from DataTime field?
for example, I'm trying to write this business rule
var gdt = new GlideDateTime ("2017-03-31 15:13:43");
year = gdt.getYearUTC();
month = gdt.getMonthUTC();
day = gdt.getDayOfMonthUTC();
hour =
minute =
second =
Thanks,
Best Regards.
Ravi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2018 04:15 PM
I don't think we have OOB API to extract those values, you can try to use.
var gdt = new GlideDateTime ("2017-03-31 15:13:43");
var gdtsplit = gdt.getDisplayValue().split(' ')[1].split(':');
var hour = gdtsplit[0];
var minute = gdtsplit[1];
var second = gdtsplit[2];

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2018 04:21 PM
Try this
var gdt = new GlideDateTime("2017-03-31 15:13:43");
var timeSection = gdt.toString().split(' ')[1]; //Gets the Time
year = gdt.getYearUTC();
month = gdt.getMonthUTC();
day = gdt.getDayOfMonthUTC();
hour = timeSection.split(':')[0];
minute = timeSection.split(':')[1];
second = timeSection.split(':')[2];
gs.addInfoMessage(hour +'-'+minute +'-'+second);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2018 05:12 PM
Hi Ravi,
You will need to do this Server side and not client side.
I would also ensure you use getByFormat to ensure that the format never changes on you ( 24 hours vs 12 hours )
var gdt = new GlideDateTime("2014-08-31 08:00:00");
var gt = gdt.getTime()
var timeStr = gt.getByFormat('hh:mm:ss');
//var timeStr = gt.getByFormat('HH:mm:ss'); // 24 hour format
var split = timeStr.split(":");
gs.info(split[0]);