how to convert date Time to customer timezone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 03:34 AM
Hi All,
I have strucked with timezone while converting GlideDateTime to user's timezone.Can anyone help me how to convert to user's timezone.
Below code is written in after update inorder to calculate delivery time and set in due date on RITM and TASK.
(function executeRule(current, previous /*null when async*/) {
var dueDate = current.due_date.getDisplayValue();
var nowDate1 = gs.nowDateTime();
var deliveryTime ='';
var totalTime = '';
var expectedTime = current.cat_item.delivery_time.getDisplayValue().toString();
deliveryTime = expectedTime.split(' ')[0];
var gdt = new GlideDateTime(nowDate1);
gdt.addDays(deliveryTime);
gs.log('gdt - ' + gdt,'swathi');
totalTime = gdt;
gs.log('totalTime' + totalTime,'swathi');
var sc = new GlideRecord('sc_task');
sc.addQuery('request_item', current.sys_id);
sc.query();
if(sc.next()){
gs.log('inside Task','swathi');
sc.due_date = totalTime.getDisplayValue();
sc.update();
}
current.due_date = totalTime.getDisplayValue();
current.update();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 03:38 AM
Hello Swathi,
Refer below similar threads may helpful to you.\
convert date time into local timezone
How to convert GMT date to EST
Hi , I want convert on timezone to another timezone .
Convert UTC to Time Zone (US/Eastern) from GlideRecord query output
ServiceNow Commnunity MVP -2018 class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 04:41 AM
Hi Swathi,
Following script will help you convert the timezone in the user's timezone in whose session the business rule will run.
var dueDateTime = new GlideDateTime();
dueDateTime.setDisplayValue(current.due_date); // get the due date
var deliveryTime = dueDateTime.getValue(); // delivery time will be in user's timezone
// do the calculation and then assign using setValue()
current.setValue('due_date',deliveryTime);
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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-07-2017 01:48 AM
Hi Ankur,
Thank you for your reply..
I tried with below script... i got it...
(function executeRule(current, previous /*null when async*/) {
var deliveryTime ='';
var expectedTime = current.cat_item.delivery_time.getDisplayValue().toString();
deliveryTime = expectedTime.split(' ')[0];
var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime();
gdt.setTZ(tz);
gdt.addDays(deliveryTime);
//gs.log('gdt - ' + gdt,'swathi');
var sc = new GlideRecord('sc_task');
sc.addQuery('request_item', current.sys_id);
sc.query();
if(sc.next()){
sc.due_date = gdt;
sc.update();
}
current.due_date = gdt;
current.update();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 01:57 AM
Hi Swathi,
Just to add a note
Never use current.update in a Business Rule.
Below post might be helpful
Never use current.update in a Business Rule