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

Adding hours to datetime variable in javascript

  • April 30, 2025
  • 1 reply
  • 641 views

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);

Best answer by _Manoj_Kumar_

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());

1 reply

_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
RajeshBhat
New Participant
May 1, 2025

Thanks @_manoj_kumar_ , that worked!