
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2021 09:29 AM
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 ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2021 09:44 AM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2021 09:39 AM
Yes, you can do that. Can you post your code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2021 09:44 AM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2021 09:46 AM
Note: this is sample code which you will use in script include .