Adding hours to Date/Time field with a script in Flow Designer.

blairf
Giga Expert

I thought this would be simple but I'm not getting the expected results.  In a Flow, I have a step to set the Planned Start Date for all Change Tasks belonging to a given Change.  That step is successful.  But then I'm working on adding/substracting hours to that Planned Start Date, and it never updates the field.  My script is:

var adjusttime = fd_data._2_1__update_record.record.planned_start_date;
adjusttime.addHours(7);
return adjusttime;
 
 
1 ACCEPTED SOLUTION

Naveen Sagar S1
Mega Guru

You can use GlideDateTime() for adding the time and you cannot add hours directly, you just have to convert the hours into seconds by multiplying with 60*60

In the below example it will add 12 hours.

var gdt = new GlideDateTime(current.start_date);
var hours = 60*60*12;
gdt.addSeconds(hours);

 

View solution in original post

1 REPLY 1

Naveen Sagar S1
Mega Guru

You can use GlideDateTime() for adding the time and you cannot add hours directly, you just have to convert the hours into seconds by multiplying with 60*60

In the below example it will add 12 hours.

var gdt = new GlideDateTime(current.start_date);
var hours = 60*60*12;
gdt.addSeconds(hours);