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

  • April 30, 2025
  • 1 reply
  • 658 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
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
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  | https://themartech.pro
RajeshBhat
Level 3
May 1, 2025

Thanks @_manoj_kumar_ , that worked!