How to add duration field type to date time field?

KARTIK17
Tera Contributor

How to add the duration field(days and hours) to the date time field dynamically and store the result in date time format?
eg.
sla time = 5 days 1 hour
due date = current time(2023-11-28 08:10:50)  + sla time

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @KARTIK17 

 

You need to write a Script for this :-

 

var sla = current.sla_time;
var datetime =sla.split(" ");
var date = datetime[0];
var time = datetime[2];

var gdt = new GlideDateTime(gs.nowDateTime());
gdt.addDays(date);
gdt.addSeconds(3600*time);
current.due_date=gdt;

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

View solution in original post

5 REPLIES 5

Samaksh Wani
Giga Sage
Giga Sage

Hello @KARTIK17 

 

You need to write a Script for this :-

 

var sla = current.sla_time;
var datetime =sla.split(" ");
var date = datetime[0];
var time = datetime[2];

var gdt = new GlideDateTime(gs.nowDateTime());
gdt.addDays(date);
gdt.addSeconds(3600*time);
current.due_date=gdt;

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

hey @Samaksh Wani 

 

 

 

 

var gr new GlideRecord('u_tablename');
gr.addQuery('record=000001111'');
gr.query();
if(gr.next()){
var sla = gr.sla_timer.getDisplayValue(); }
gs.info(sla);
var dateTime = sla.split(' ');
var date = dateTime[0];
var hours = dateTime[2];
var minutes = dateTime[4];
var seconds = dateTime[6];
gs.info(minutes);
var gdt = new GlideDateTime('2023-11-28 08:31:00');
gdt.addDaysLocalTime(date);
gdt.addSeconds (3600*hours);
gdt.addSeconds (60*minutes);
gdt.addSeconds (seconds);
gs.info(gdt);

 

 

 

Can you help me with the error it is through while reading that addSeconds function for the seconds value of the field?
please find the executions attachment
 

Hello @KARTIK17 

 

modify your line with mine :-

 

gdt.seconds(seconds);

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

 

Hi @Samaksh Wani , Thanks for quick response.

Even after modifying your line, it throws an error that it is not a function.
Can you please check the attachment, The getDisplayValue function on the sla timer is not displaying seconds even though the second value is there in the duration field.
How to overcome this challenge.?