Adding 1 hour to current date is not working as intended

Manoj82
Kilo Expert

Hi,

I have a requirement to set the time from a UI page onto a scheduled job based on the current time

script :(to update the time on the job)

var gdt = new GlideDateTime(gs.nowDateTime());
var hours = 60*60*1;
gdt.addSeconds(hours);

and based on this I set my schedule job date:
rec.run_start = gdt.getValue();

Instead of updating the time on scheduled job to next hour )irrespective of AM or PM ) it only update the job date to AM 

Can you please tell me what is the issue and how to fix this

Regards,
Manoj

8 REPLIES 8

Mike Patel
Tera Sage

you can do below

var gdt = new GlideDateTime();
var hours = 60*60*1;
gdt.addSeconds(hours);
rec.run_start = gdt.getDisplayValue();

Manoj82
Kilo Expert

HI Mike,

I think, if you look into my script it has the same code:

var hours = 60*60*1;

The major issue is 

var hours = 60*60*1; will work if the current time is in AM and 
var hours = 60*60*13; will work if the current time is in PM

I am looking to fix the script in such a way that it is dynamic in both AM and PM

Regards,
Manoj

Manoj,

If you look at my script difference is not hours. adding seconds has nothing to do with AM and PM.

var gdt = new GlideDateTime();

Hi Mike,

I tried the script you mentioned and run my UI page at 10:45:01 AM (current time) and the job updated to 12-11-2018 07:45:01 PM based on this script (9hours have been added)
find_real_file.png

 

var gdt = new GlideDateTime(gs.nowDateTime()); is working fine for the 60*60*1 during the AM.

Regards,
Manoj