
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 08:41 AM
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.
Davide.
Solved! Go to Solution.
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 10:11 AM
Hi Davide,
Interesting we don't seem to have any methods available to easily get a handle to these values, however if you want a quick answer (considering its almost close of business on a Friday), you could use the getValue() method.
This returns a String of the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and importantly the system time zone, UTC by default.
From this you could use the String methods available to get a handle to these values. Foe example the split method and/or substring method etc.
Not the cleanest of solutions but I'll take a look later for you.
Please mark this response as correct and helpful via your post link (GlideDateTime - get hours, minutes and seconds ) to help others with the same question.
Thanks,
Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 10:11 AM
Hi Davide,
Interesting we don't seem to have any methods available to easily get a handle to these values, however if you want a quick answer (considering its almost close of business on a Friday), you could use the getValue() method.
This returns a String of the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and importantly the system time zone, UTC by default.
From this you could use the String methods available to get a handle to these values. Foe example the split method and/or substring method etc.
Not the cleanest of solutions but I'll take a look later for you.
Please mark this response as correct and helpful via your post link (GlideDateTime - get hours, minutes and seconds ) to help others with the same question.
Thanks,
Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 01:26 AM
Hi Davide,
How did you go?
Please mark this response as correct and helpful via your post link (GlideDateTime - get hours, minutes and seconds ) to help others with the same question.
Thanks,
Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2020 11:36 PM
There is a straightforward way to get hour, mins and second from any given date.
GlideDateTime provide getTime method, which returns GlideTime object.
GlideTime has api to return you all the time related data.
var gdt = new GlideDateTime("1970-01-01 06:02:31");
gt = gdt.getTime();
gs.info('hours is:'+gt.getHourUTC())
gs.info('minutes is:'+gt. getMinutesUTC())
gs.info('seconds is:'+gt. getSeconds())
This is the recommended way to obtain time.
Here are the api for reference
https://developer.servicenow.com/dev.do#!/reference/api/madrid/server/r_SGT-getSeconds
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/r_GDT-GlideDateTime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 01:05 PM
I tried this in a business rule and getting following error:
Function getTime is not allowed in scope global
Do you know why?
~Thanks