How do I perform arithmetics on date field

Yi Ming Song
Tera Contributor
  • Hi, I have a date field which I want to write a business rule for. I have a due_date field and I want to generate reminder when it is 50% towards the due date. 
  • To do this I also have a reminder_date field which I want to populate with an insert business rule to calculate the reminder_date based on due_date.
  • When I use GlideDateTime.subtract(), it returns undefined. 
  • Are there any ways to perform arithmetic operations on date fields in business rules?
3 REPLIES 3

RyanQ
Tera Contributor

Reference to Production API:

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAP...

 

- addDays(Number days)

- add(GlideTime time)

Hope one of these functions can help

Amit Verma
Kilo Patron
Kilo Patron

Anubhav24
Mega Sage
Mega Sage

Hi @Yi Ming Song ,

Before doing the subtraction can you convert the dates using getNumericValue() functions it converts the date to milliseconds and then you can simply do the subtraction no need to use the subtract function and once you have the value of the date you can set it back using setNumericValue().

 

Please mark helpful/correct if my response helped you.