Issue in calculating time difference in different timezone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 11:14 PM
Hi Team,
My system timezone is in EST and servicenow timezone is in IST. Below are the script which calculate time difference but its not working properly.
Catalog Client Script:-
BIIB_CPGResizeConfirmDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCurrDate: function() {//Check if given Date time is in past or not.
var ActualEndDate = this.getParameter('sysparm_time');
var dif = gs.dateDiff(gs.nowDateTime(), ActualEndDate, true);
if (dif < 1800) {
return false;
} else {
return true;
}
},
chkstartstopDate: function() {//Check if given Date time is in past or not for start stop.
var ActualEndDate = this.getParameter('sysparm_time');
var dif = gs.dateDiff(gs.nowDateTime(), ActualEndDate, true);
if (dif < -2) {
return false;
} else {
return true;
}
},
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 07:06 AM
Hello Kun,
Please check with below at or before today condition once. Also if you want the validation to happen onLoad then check On load checkbox: Replace your field name in filter condition. Also if you want to allow today's date then change the filter to at or before Yesterday
function onCondition() {
g_form.clearValue("start_date"); // replace your field name here
g_form.showFieldMsg("start_date", "Please select future date", "error"); // replace your field name here
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 08:37 PM
I also tried this but time will take in the variable in my system time but timezone is servicenow timezone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2022 04:54 AM
Hello Kun,
Please check with below client script:
Client script on planned_start_date_time field:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue) {
var ga = new GlideAjax('CustomClientDateTimeUtils');
ga.addParam('sysparm_name', 'compareToCurrentTime');
ga.addParam('sysparm_selected_time', newValue);
ga.getXMLAnswer(parseReceivedData);
}
function parseReceivedData(answer) {
alert(answer);
if (answer == "false") {
g_form.clearValue("planned_start_date_time");
g_form.showFieldMsg("planned_start_date_time", "Please select future date", "error");
}
}
}
Script Include where Client callable is checked: Script will get the current time in user's timezone and compare with the date time selected by user as per his timezone:
var CustomClientDateTimeUtils = Class.create();
CustomClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareToCurrentTime: function() {
var selectedTime = this.getParameter("sysparm_selected_time");
var selectedGDT = new GlideDateTime();
selectedGDT.setDisplayValue(selectedTime);
var selectedTimeInUserTZ = selectedGDT.getDisplayValue();
var currentGDT = new GlideDateTime();
var currentTimeInUserTZ = currentGDT.getDisplayValue();
if (selectedTimeInUserTZ < currentTimeInUserTZ) {
return false;
} else {
return true;
}
},
type: 'CustomClientDateTimeUtils'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 01:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 01:50 AM