How to use GlideDateTime.subtract output

Artur Poswiata1
Kilo Contributor

Hello,

I want to check difference between two dates, and based on that change background of the field.

For so far in client script I'm take the due_date from form and pushing it to include script.

In include script I'm subtracting today date and the due date.

I receive the difference like "2 Days 34 min 40 sec".

What i want to achieve is that:

If diff is more than 24h then makes filed background color on green (I know how to makes filed highlighted)

If diff is less than 24h then makes filed background color on yellow

What i can put in if statement to achieve the goal ?

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

To get difference in hours , can you try like this, 

 

var start = new GlideDateTime("2016-08-28 09:00:00");
var end = new GlideDateTime("2016-08-29 09:10:00");


// Duration in hours

var dur_seconds = gs.dateDiff(start, end, true); 

var dur_hours = Math.round(dur_seconds / 3600);

gs.print(dur_hours); // this will give 24 hours

if(dur_hours > 24){
//do the action for more than 24 hours
}



else if(dur_hours < 24){
//do the action for more less than 24 hours
}

View solution in original post

3 REPLIES 3

Elijah Aromola
Mega Sage

Yes, you can do that. Can you post your code?

Harsh Vardhan
Giga Patron

To get difference in hours , can you try like this, 

 

var start = new GlideDateTime("2016-08-28 09:00:00");
var end = new GlideDateTime("2016-08-29 09:10:00");


// Duration in hours

var dur_seconds = gs.dateDiff(start, end, true); 

var dur_hours = Math.round(dur_seconds / 3600);

gs.print(dur_hours); // this will give 24 hours

if(dur_hours > 24){
//do the action for more than 24 hours
}



else if(dur_hours < 24){
//do the action for more less than 24 hours
}

Note: this is sample code which you will use in script include .