- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 06:50 PM
Hi I have to add time to date field. Please help me on how to achieve this
Example, I have below two fields:
( Date Type field ) EventDate : 09/11/2017
(Time Field) EventTime : 13:00:00
Now I have to calculated the StartDateTime and EndDateTime Values:
StartDateTime = EventDate and Event Time which should be 09/11/2017 13:00:00
EndDateTime = StartDateTime + 30 min i.e, it should be 09/11/2017 13:30:00
Can any one through some light on what date functions can be used to achieve this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 02:10 PM
Figured out the solution. Achieved it with below script
var gr = new GlideRecord("tablename");
gr.addQuery('sys_id',"recordsysid");
gr.query();
if(gr.next()){
var date = gr.u_event_date.getDisplayValue();
var time = gr.u_event_time.getDisplayValue();
var datetime = date + ' ' + time;
var period = 30*60; //covert 30 min to seconds
var gdt = new GlideDateTime();
gdt.setDisplayValue(datetime);
gs.print('gdt=' + gdt.getValue());
gr.u_start_date.setValue(gdt);
var gdt2 = new GlideDateTime(gdt);
gdt2.addSeconds(period);
gr.u_end_date.setValue(gdt2);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 09:13 PM
Server-side: http://wiki.servicenow.com/?title=GlideDateTime#gsc.tab=0
Client-side: JavaScript Date Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 10:31 PM
Hi ,
You can use the below script.
var dt = new GlideDate();
dt.setValue("2017-3-11");
var time = new GlideTime();
time.setValue("1:00:00")
var gdt = new GlideDateTime(dt);
gs.info(gdt.getDisplayValue());
gdt.add(time);
gs.info(gdt.getDisplayValue());
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 02:10 PM
Figured out the solution. Achieved it with below script
var gr = new GlideRecord("tablename");
gr.addQuery('sys_id',"recordsysid");
gr.query();
if(gr.next()){
var date = gr.u_event_date.getDisplayValue();
var time = gr.u_event_time.getDisplayValue();
var datetime = date + ' ' + time;
var period = 30*60; //covert 30 min to seconds
var gdt = new GlideDateTime();
gdt.setDisplayValue(datetime);
gs.print('gdt=' + gdt.getValue());
gr.u_start_date.setValue(gdt);
var gdt2 = new GlideDateTime(gdt);
gdt2.addSeconds(period);
gr.u_end_date.setValue(gdt2);