On change client script to calculate the difference in start date and end date and display the result in another field no_of_days in days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 03:52 AM
I have two fields start date and end date for my table.I wanted to write an onchange client script such that upon selection of both dates the difference in dates should be auto populated in no-of_days field which is of type integer.
For eg:If start date is 09-09-2020 and end date is 11-09-2020 The no_of_days field should have 3.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 12:16 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate answer as correct & helpful to close the thread.
If not, please let us know if you need some more assistance.
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
‎09-14-2020 08:11 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate answer as correct & helpful to close the thread.
If not, please let us know if you need some more assistance.
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
‎09-22-2020 07:46 AM
Hi Deepika,
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate answer as correct & helpful to close the thread.
If not, please let us know if you need some more assistance.
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
‎09-23-2020 06:04 AM
You can do something similar with only one line of code using functional fields
glidefunction:datediff(opened, resolved_at)
datediff()
Takes 2 date/time fields as input, calculates the difference between the dates in days, minutes, and seconds, and returns the results as a duration field value.
https://docs.servicenow.com/bundle/paris-platform-administration/page/build/platform-functions/concept/platform-support-functions.html
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2024 12:19 PM
I know this is an old thread, but you just saved me hours of work. Thank you for the heads up on Function fields!