- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2019 07:56 AM
Hi, I have a date/time variable as an input and I am trying to calculate the duration in seconds from the current moment (now) till the date/time selected in the date/time field.
I saw some examples and am currently trying with the below one but am getting the following error and cannot figure what is going wrong:
org.mozilla.javascript.WrappedException: Wrapped org.mozilla.javascript.EvaluatorException: Can't find method com.glide.glideobject.GlideDateTime.subtract(java.lang.String,com.glide.glideobject.GlideDateTime).
Thanks!
Jeny
// Set 'answer' to the number of seconds this timer should wait
var gdt1 = GlideDateTime();
gs.addInfoMessage("date now: "+gdt1);
var gdt2 = new GlideDateTime(gdt1.getDisplayValueInternal());
gs.addInfoMessage("date now using internal value: "+gdt2);
var gdt = new GlideDateTime(current.variables.destroy_after.getValue());
var gdt3 = gdt.getDisplayValueInternal();
gs.addInfoMessage("workflow end date is: "+gdt3);
var duration = GlideDateTime.subtract(gdt3,gdt2);
gs.addInfoMessage("duration is: "+duration);
answer = (duration.getNumericValue() / 1000);
gs.addInfoMessage("answer is " + answer);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2019 03:34 AM
Hi Alexey,
Your suggestion didn't work but this below worked eventually.
var gdt1 = GlideDateTime();
gs.addInfoMessage("date now: "+gdt1);
var gdt2 = new GlideDateTime(gdt1.getDisplayValueInternal());
gs.addInfoMessage("date now using internal value: "+gdt2);
var gdt3 = new GlideDateTime(current.variables.destroy_after).getDisplayValueInternal();
gs.addInfoMessage("workflow end date is: "+gdt3);
var dur_seconds = gs.dateDiff(gdt2, gdt3, true);
gs.addInfoMessage("duration is: "+dur_seconds);
answer = dur_seconds;
gs.addInfoMessage("answer is " + dur_seconds);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2019 08:05 AM
This link has two approaches to calculate the difference
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2019 08:37 AM
Hi Harshinya,
Thanks for the link! I did some changes and this below worked for me, only I do not know how to take the gdt3 in my selected time zone and preserve that the var is an object. I get 2h difference currently.
var gdt1 = GlideDateTime();
gs.addInfoMessage("date now: "+gdt1);
var gdt2 = new GlideDateTime(gdt1.getDisplayValueInternal());
gs.addInfoMessage("date now using internal value: "+gdt2);
var gdt3 = new GlideDateTime(current.variables.destroy_after);
gs.addInfoMessage("workflow end date is: "+gdt3);
var dur_seconds = gs.dateDiff(gdt2, gdt3, true);
gs.addInfoMessage("duration is: "+dur_seconds);
answer = dur_seconds;
gs.addInfoMessage("answer is " + dur_seconds);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2019 08:41 AM
Hi,
you can use getTZOffset() method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2019 03:34 AM
Hi Alexey,
Your suggestion didn't work but this below worked eventually.
var gdt1 = GlideDateTime();
gs.addInfoMessage("date now: "+gdt1);
var gdt2 = new GlideDateTime(gdt1.getDisplayValueInternal());
gs.addInfoMessage("date now using internal value: "+gdt2);
var gdt3 = new GlideDateTime(current.variables.destroy_after).getDisplayValueInternal();
gs.addInfoMessage("workflow end date is: "+gdt3);
var dur_seconds = gs.dateDiff(gdt2, gdt3, true);
gs.addInfoMessage("duration is: "+dur_seconds);
answer = dur_seconds;
gs.addInfoMessage("answer is " + dur_seconds);