- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2023 07:41 AM
I am trying to calculate a future date and time for a field that I need to populate in a script found within a Scheduled Job. Basically, I need to go 3 days from the current date, and choose 5:00 AM that day.
So, if today is February 10, 2023, the dynamic date calculation should return February 13, 2023 5:00 AM.
I found the "gs.dayAgo" function, but that does not return time.
So if I try to use it like this:
gr.scheduled=gs.daysAgo(-3);
It returns February 13, 2023 12:00 AM instead of February 13, 2023 5:00 AM (right day, wrong time).
How can I get it to add the 5:00 AM time?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2023 04:12 PM
Hi, try this:
var dt = new GlideDate();
dt.addDays(3);
var dt2 = new GlideDateTime();
dt2.setValue(dt.getValue() + ' 05:00:00');
gr.scheduled = dt2;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2023 01:06 PM
First, please see:
And post your entire script. Others here may have better ideas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2023 01:51 PM
var dt = new GlideDateTime();
gs.info("script include: dt = " + dt + ".");
dt.addDays(-3);
var pdt = dt.getDate();
gs.info("script include: pdt = " + pdt + ".");
var desiredDateTime = new GlideDateTime(pdt+" 05:00:00");
gs.info("script include: desiredDateTime = " + desiredDateTime + ".");
/* following doesn't work
gr.scheduled=gs.daysAgo(-3);
gs.info("gr.scheduled = " + gr.scheduled + ".");
*/
Test in the script of a Scheduled Job set to run "On Demand". See results in the Script Log Statements module.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 06:56 AM
This is also helpful and very close to what I needed. Just need to change this part:
dt.addDays(-3);
to this:
dt.addDays(3);
as I originally had
.daysAgo(-3)
so if you switch the function, you also need to switch the sign.
Thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2023 04:12 PM
Hi, try this:
var dt = new GlideDate();
dt.addDays(3);
var dt2 = new GlideDateTime();
dt2.setValue(dt.getValue() + ' 05:00:00');
gr.scheduled = dt2;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 06:53 AM
Yes, that is exactly what I was looking for.
I think the problem I was having what I was using "GlideDateTime" for my first date, so adding 5 hours added 5 hours to the current time, and not from midnight.
Thank you!