Am I using .addDays incorrectly? (UTC time returning)

Travis Michigan
Mega Sage

I have a flow that is taking a date with time, and I'm trying to add a day to it in a cycle so that it can create one for each day of the week, but also is checking this against another flow to make sure that it is a business day and not a holiday.  The subflow is also used for time so the time matters too.  I have the following and when I use this it ends up changing the time to UTC, which is five hours later, and then will sometimes fail due to time of day.  Is there a different way I should be formatting this?  I've tried a few versions like .addDaysLocalTime() and a few other things, but maybe there is something else I'm doing wrong.  Thank you for any tips!

var returnDate = new GlideDateTime();
returnDate.setDisplayValue(fd_data.flow_var.date);
returnDate.addDays(1);
return returnDate.getDisplayValue();

 

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @Travis Michigan ,

 

It could be because 'fd_data.flow_var.date' retrieves the time in the system timezone and you are using it as the 'display value'.

You should be able to fix this by either:

  1. change 'fd_data.flow_var.date' to 'fd_data.flow_var.date.getDisplayValue()', OR
  2. Use the system timezone instead across the script. i.e.

 

var returnDate = new GlideDateTime();
returnDate.setValue(fd_data.flow_var.date);
returnDate.addDays(1);
return returnDate.getValue();​

 

Personally, I prefer using the system timezone but that's just me 🙂

 

Hope it helps, thanks

 

View solution in original post

2 REPLIES 2

AshishKM
Kilo Patron
Kilo Patron

Hi @Travis Michigan , 

You can add the time zone parameter to variable "returnDate" as below.

Check if it works for you.

 

var returnDate = new GlideDateTime();
returnDate.setDisplayValue(fd_data.flow_var.date);
returnDate.addDays(1);
var tz = Packages.java.util.TimeZone.getTimeZone('America/New_York'); // set the timezone
returnDate.setTZ(tz);
return returnDate.getDisplayValue();

 

 

Refer some guidelines

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594666 

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

James Chun
Kilo Patron

Hi @Travis Michigan ,

 

It could be because 'fd_data.flow_var.date' retrieves the time in the system timezone and you are using it as the 'display value'.

You should be able to fix this by either:

  1. change 'fd_data.flow_var.date' to 'fd_data.flow_var.date.getDisplayValue()', OR
  2. Use the system timezone instead across the script. i.e.

 

var returnDate = new GlideDateTime();
returnDate.setValue(fd_data.flow_var.date);
returnDate.addDays(1);
return returnDate.getValue();​

 

Personally, I prefer using the system timezone but that's just me 🙂

 

Hope it helps, thanks