GlideDateTime.subtract doesn't work

abrouf
Kilo Sage

I used the following commands on default value to calculate the number of days subtracting current date to due date but didn't work. Any comment or advise is greatly appreciated.

javascript:calendar_duration = GlideDateTime.subtract(due_date.getDisplayValue(), gs.nowDateTime());

Following this syntax:

<duration_field> = GlideDateTime.subtract(<start_field>.getDisplayValue(),gs.nowDateTime());

21 REPLIES 21

HarshTimes
Tera Guru

HI Rouf


You are missing object for the due date.




OBJECT.due_date.getDisplayValue()


andymcdonald
Kilo Guru

if dueDate is a GlideDateTime, you just do the following:



GlideDateTime.subtract(due_date, gs.nowDateTime());


Prateek kumar
Mega Sage

Hello Mohammed


This thread will help you


How to set Calculated Value for Duration (or any other date/time) field



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Gowrisankar Sat
Tera Guru

Try if this works:



Following this syntax:


<duration_field> = GlideDateTime.subtract(new GlideDateTime(current.due_date),gs.nowDateTime());