Set Date and Time to Next Day at Specific TIme
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2017 12:39 PM
I'm attempting to set the date and time for a field on a catalog item. I'm calling it a "Need by Date". The requirement is to default the date and time 1 day out, and set the time to 7:00:00 that day. Can someone help configure this? I'm using a GlideDateTime (addDay(1)) and GlideTime (setValue) which is adding 7 hours to the current date/time.
Here's the script I'm using:
javascript:
var gdt = new GlideDateTime();
var gtime1 = new GlideTime();
gdt.addDays(1);
gtime1.setValue("07:00:00");
gdt.add(gtime1);
gdt.getDisplayValue();
Here is What's Happening:
If the current date and time were: 02-09-17 15:00:00
The catalog item form will load and display: 02-10-17 22:00:00
Any help is appreciated!
Thanks,
-Marques

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 08:19 AM
Andy,
Actually, what you have above is what I need. I am trying to figure out two things:
Where do you set this javascript to run? Is this code plugged into a client script, dictionary, other??
How do you set the value of 'gdr' to a specific field (like u_notification_date)?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 08:24 AM
Hey matthew.magee,
I work with Andy and can answer your first question. I set this at the default value of the Date/Time field. Andy will have to speak on behalf of your other question.
-Marques

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 08:36 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 09:03 AM
Update to my update:
I threw in some log statements:
javascript:
var gdt = new GlideDateTime();
gdt.addDays(1);
gs.log('GDT: ' +gdt);
var tmrwAtSeven = gdt.toString().slice(0,10) + " 07:00:00";
gs.log('GDT2: ' + tmrwAtSeven);
var gdr = new GlideDateTime(tmrwAtSeven);
gs.log('GDT3: ' + gdr);
All three log entries appear:
For some reason, i just can't get the new time stamp to show up on the form, it is still blank.
Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2017 09:55 AM
Hey matthew.magee
Looks like you're missing a 'Get Display Value' at the end of the script.
Try adding this to the end: gdr.getDisplayValue();
Lastly, I think andypollino last paragraph in the post is important:
"Now GDR is tomorrow at 7 (GMT). You should adjust the 07 if you're not in GMT! For example, if you want gdr to be 7:00am in EST, 07:00:00 should be 14:00:00 instead. Then, if a user on the US's East Coast does gdr.getDisplayValue(), it should display tomorrow's date as YYYY-MM-DD 07:00:00"
I tested your script in my personal developer instance and it should work now- Although I tried it in the 'Planned Start Date' field
javascript:
var gdt = new GlideDateTime();
gdt.addDays(1);
var tmrwAtSeven = gdt.toString().slice(0,10) + " 07:00:00";
var gdr = new GlideDateTime(tmrwAtSeven);
gdr.getDisplayValue();
Hope that helps!
-Marques