How To Check Difference Between Two Dates Using Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 03:40 AM - edited ‎01-08-2023 03:40 AM
Hello all,
I want to find the difference between the incident creation date and the updation date. I am getting proper output using glideajax but now I want to achieve the same functionality using g_scratchpad. I have written code for that but am not getting proper output using g_scratchpad..
can anyone please guide me on this?
Thank You.
*-----------------------g_scratchpad code-----------------------*
Used Display BR
// var gd1=new GlideDateTime();
// gd1.setDisplayValue(current.sys_created_on);
// var gd2=new GlideDateTime();
// gd2.setDisplayValue(current.sys_updated_on);
// var duration=GlideDateTime.subtract(gd1,gd2);
g_scratchpad.d=duration.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 03:41 AM
Hi,
Along with a display BR you have to write a client script to access the g_scratchpad variable at client side.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 04:12 AM
hello i tried with onload client script but not getting output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 04:35 AM
Hello Abhi ,
I have Included Sample script which executes at Client Script for date difference
Date Range Comparison.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Date to be between Jan 15th and Feb 15th only.
//assuming date format of SN is dd/mm/yyyy. so create 2 dates in that format.
var start_dateStr = formatDate(new Date(getDateFromFormat("15/01/2020 00:00:00",g_user_date_time_format)),g_user_date_time_format);
var start_dateNum = getDateFromFormat(start_dateStr,g_user_date_time_format);
var end_dateStr = formatDate(new Date(getDateFromFormat("15/02/2020 00:00:00",g_user_date_time_format)),g_user_date_time_format);
var end_dateNum = getDateFromFormat(end_dateStr,g_user_date_time_format);
var selected_dateNum = getDateFromFormat(newValue,g_user_date_time_format);
if(selected_dateNum < start_dateNum || selected_dateNum > end_dateNum) {
g_form.showFieldMsg('expected_start','Date should be between Jan 15th 2020 and Feb 15th 2020','error',true);
} else {
g_form.hideFieldMsg('expected_start',true);
}
}
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 05:23 AM
Hey,
As I see your pasted code, you have commented the first four script statements and then directly assigning the value of 'duration' variable. May be that's the case.
Below is the same logic and screenshot which I have implemented it's working fine.
Client script
Incident-
Hope this helps!
Regards,
Kartik Choudhary