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-11-2022 07:01 AM
@kun
So what did not work fine?
what debugging did you perform?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 01:39 AM
First issue is on form variable take in time as per my system time but time zone is as per my Servicenow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2022 08:19 PM
No worries on that.
UI Policy condition should take that into account.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2022 11:58 PM
Hi Ankur,
We have tried with the UI policy also. So, if my System time is in EST and servicenow is in IST then the time taken on portal is the browser time(System time) . So, suppose if i select 14/09/2022 2:51 AM then time mention is in IST but time zone is EST . so when EST user open RITM in ITIL view time change from 14/09/2022 2:51 AM to EST time and that is the past time.
IST time is now 14/sep/2022 12:22 PM but in the variable time taken from my system time(est) which is past time
it should show error here that please select future date.
After submission:-
User having IST time zone
User having EST timezone
i think you understand the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 06:31 AM
Hi Kun,
You can try below script to convert your field time zone to required time zone:
var gDate = Packages.com.glide.glideobject.GlideDateTime(planned_start_date_time);
//converting GMT to Canada/Eastern
var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");
// Put Time Zone based on your requirement
var pDate = gDate.setTZ(tz);
gs.log(pDate); // Just to test the value of Date/Time Field in different Timezone
Than you can compare both fields in same time zone.
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