
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 08:51 AM
I am new to JavaScript in SN, but I have a good developer's experience in other tools/languages.
I am trying to use a Function field in London release to calculate the datediff between Now and pause_time in a Task_SLA table. According to documentation, and I have already done this, I can do something like this: glidefunction:datediff(resolved_at,sys_created_on), but these are regular fields on an Incident records. I need to use a Current date to subtract pause_time. Is it even possible to use a dynamic date?
I tried the below, but I am getting result of 0 sec
glidefunction:datediff(javascript:gs.nowDateTime(),sys_created_on)
glidefunction:datediff(gs.nowDateTime(),sys_created_on)
glidefunction:datediff(nowDateTime(),sys_created_on)
Please help!!!!!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 10:57 AM
datediff is different than gs.dateDiff. The glidefunction version takes field names as inputs, not date/time values. So you would need another field that stores the current date/time which I am assuming would be an issue for your use case if you are using a function field instead of some other options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 10:57 AM
datediff is different than gs.dateDiff. The glidefunction version takes field names as inputs, not date/time values. So you would need another field that stores the current date/time which I am assuming would be an issue for your use case if you are using a function field instead of some other options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 02:23 PM
I miraculously found that using "now()" as one of the inputs allows you to compare a date/time field with the current date time. The 'Type' field should be "Duration" and the 'Function definition' field would be this:
glidefunction:datediff(now(),sys_created_on)
That's not documented anywhere (not surprising, unfortunately), but it is now! Make sure the "earlier" date/time is second in the input list, otherwise, you'll get an odd result. If you needed to display the duration since a certain field value, use what is above. If you need to display the duration to a certain field value, like Planned Start Date on a change request, use this:
glidefunction:datediff(start_date,now())
Let me reiterate that this only produces good values if the first input is "later" than the second input. If your use case requires something else, I think you'd need to use GlideDBFunctionCaseBuilder and cross your fingers that you can figure it out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 09:16 PM
This gives me an error saying "now is not a supported function , Script error in script." Did you have to update anything else to get it to work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 09:09 AM
In another Community thread, I noted that this only works from the Dictionary view, not the reporting interface. Hopefully that's the issue you're experiencing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2019 12:20 PM
Apparently Function Fields have been broken in Madrid and being promised to be fixed in Orlando.