Issue in calculating time difference in different timezone

kun1
Tera Expert

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:-

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading)
 
    {
 
        return;
 
    }
 
    //start the validation for star date time.
 
 
    if (newValue != '')
 
    {
        var ga = new GlideAjax('BIIB_CPGResizeConfirmDate');
        ga.addParam('sysparm_name', 'chkstartstopDate');
        ga.addParam('sysparm_time', g_form.getValue('planned_start_date_time'));
        ga.getXML(NewParse);
    }
 
    function NewParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == 'false') {
            alert("Please select a future date");
            g_form.setValue('planned_start_date_time', '');
 
        }
    }
}
 
Script include:-
var BIIB_CPGResizeConfirmDate = Class.create();
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;
        }
    },
    
});
 
it will not calculating time diff properly when system(EST) and servicenow (IST) timezone is diff
22 REPLIES 22

but this will convert it into eastern but we are not sure like what end user timezone is ?

Than better you can convert both fields into eastern timezone and compare if you are not sure on time zone. This will make it more generic.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

what i am think to covert timezone in GMT and then compare . but i am not able to recall GlideDateTime in above mentioned code.

 

Can you please modify it in GlideDateTime()?

Hi Kun,

var gDate = Packages.com.glide.glideobject.GlideDateTime(planned_start_date_time);

What value are you getting here?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

This we need to use in script catalog client script or in script include?

and where we need to call this package? Can you modify above script accordingly?