Adding hours to datetime variable in javascript | Community
Skip to main content
RajeshBhat
Level 3
April 30, 2025
Solved

Adding hours to datetime variable in javascript

I have a below code written in js activity. I need to add 1 hour to the variable currDate. How can I do that? I tried with setHour() and + operator without luck.

 

 

vars.currDate = new Date();

logInfo("vars.currDate----------" + vars.currDate);

_Manoj_Kumar_
_Manoj_Kumar_Accepted solution
New Participant
May 1, 2025

Hello @rajeshbhat  This is how the setHours will work.

 

var now = new Date(); logInfo("Current Date: "+ now.toISOString()); now.setHours(now.getHours() + 1); logInfo("New time (1 hour ahead): " + now.toISOString());
     Manoj     Find me on LinkedIn

2 replies

_Manoj_Kumar_
_Manoj_Kumar_Accepted solution
New Participant
May 1, 2025

Hello @rajeshbhat  This is how the setHours will work.

 

var now = new Date(); logInfo("Current Date: "+ now.toISOString()); now.setHours(now.getHours() + 1); logInfo("New time (1 hour ahead): " + now.toISOString());
Translate
     Manoj     Find me on LinkedIn
RajeshBhat
Level 3
May 1, 2025

Thanks @_manoj_kumar_ , that worked! 

Translate