How to add hours to a Date/Time value?

Lakshmi Prabha
Giga Expert

Hi,

How to add hours to a Date/Time value.

I want to add 13 hours to the below Time format.

**4beginNextWeek===>2016-08-08 04:00:00

I have tried this Its din't work.

var beginNextWeek = new GlideDateTime(gs.beginningOfNextWeek());

  gs.log("**4beginNextWeek===>"+beginNextWeek);

  var splitDate = beginNextWeek.split("-"); // Split Catalog Date into year, month, day  

var termDate = new Date(splitDate[0],splitDate[1]-1,splitDate[2]); // Avoid timezone issues, but month starts at 0  

termDate.setHours(14); // 5:00 p.m. EST (2:00 p.m. PST by default)  

  gs.log("**4termDate===>"+termDate);

1 ACCEPTED SOLUTION

You might want to use getDisplayValue() to get in the user's time zone



var gdt = new GlideDateTime(gs.beginningOfNextWeek());


var hours = 60*60*13;


gdt.addSeconds(hours);


gs.print(gdt.getDisplayValue());


View solution in original post

6 REPLIES 6

Nice work around...I spent a day trying to conjur up the right incantation for some complex time duration calculations before I found this...


randrews
Tera Guru

a lot depends on where you are doing this.. is it a client side script or a server side script?