How to sum two date/time fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2020 11:08 PM
Hi All,
I want to store the time of SLA on the incident form in the custom field called Response time storage, duration type by using run script in the workflow.
My requirement is I have 3 SLAs which are defined in the business service, if we select the business service (time will be defined by the business service owner based on priority levels) on the incident form, value will be stored in the custom filed called Response time,same for another 2 SLAs which are working fine.
My concern is I want to calculate the time how long the Response sla took to complete, let's say if it starts at 10AM and ends at 11AM, It should excludes onhold and resolved time. if the incident is on hold state for 10min and in resolved state 10min, If it goes multiple times like on hold twice 10min & 10min should calculate onhold as 20 and resolved 10
Response time storage should show: 30min
If on hold first time for 1 day 2 hrs 40min & second time for 2 days 6hrs 12min and resolved state is 1day 10hrs 8 mins these three times should get calculated and subtract with the total time
How can I achieve it?
Please help with your accurate answers.
Thanks
K
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2020 11:42 PM
Hi,
To add 2 date fields, you can use GlideDateTime API and in that you can use one of the below functions based on your requirement
addDays
addMinutes
addHours
addSeconds
Note: If you need to subtract, you can still use same functions but use -ve value as a parameter.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP