Expand my Community achievements bar.

SOLVED

Adding hours to datetime variable in javascript

Avatar

Level 3

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

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 3

Thanks @_Manoj_Kumar_ , that worked!