The CreatorCon Call for Content is officially open! Get started here.

Conversion of Dates to DateTime fields

Uncle Rob
Kilo Patron

We're currently using the Relative Duration module in an effort to create an SLA that uses a user defined end time.

I managed to build this successfully in Demo, but when I started building in my own system I had a huge problem with respect to dates. I can't get my original formulation to work when the input is a date field rather than a date/time.

Is there an easy way to convert a date to datetime? I'd like to assume that the "time" is 00:00:00. It'd be even better if I could change this assumption (like 08:00:00 for example).

7 REPLIES 7

Jay_Ford
Kilo Guru

Are providing the date in a 'Date' variable in the service catalog? I've used scripts like the one below in workflows to set a specific time before where 'end_date' was the variable name on the item's form.



var theTime = '08:00:00';
var theDate = new Packages.com.glide.glideobject.GlideDateTime();
theDate.setValue(current.variable_pool.end_date.getGlideObject().getValue() + ' ' + theTime);


Uncle Rob
Kilo Patron

I actually found a wonderful little thing called gs.dateGenerate
http://wiki.service-now.com/index.php?title=GlideSystem_Date_and_Time_Functions#dateGenerate.28String.2C_String.29

So now my problem seems to be on the Relative Duration script. Its not populating the planned_end_time on the SLA record, even though I know I'm feeding it a datetime field.



var DueBy = gs.dateGenerate(current.task.u_requested_date,'00:00:00');

current.planned_end_time = DueBy.getGlideObject();
calculator.endDateTime = DueBy.getGlideObject();
var start = current.task.opened_at.getGlideObject();
calculator.seconds = ((calculator.endDateTime.getNumericValue() - start.getNumericValue()) / 1000);
calculator.totalSeconds = calculator.seconds;

gs.log('LOGME TASK ' + current.task.number + ' SLA SYS ID ' + current.sys_id + ' PET ' + current.planned_end_time + ' DUE BY ' + DueBy + ' ENTERED ' + current.task.u_requested_date);


rfedoruk - nothing like resurrecting a 3 year old post, but I'd like to know what you ended up doing here.  


  I have no recollection of this post.