We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Days between computer purchase date and install date

LouisRRonzi
Tera Guru

Anyone have a query or report for calculating the number of days between the purchase date (purchase_date) and the Installed date (install_date) in the alm_hardware table?

 

Looking for a report or procedure to create one so I can determine how many days between these two dates.

1 ACCEPTED SOLUTION

@LouisRRonzi 

 

Same logic can be extended as below if you want to store duration as integer,

Bhuvan_0-1755442242206.pngBhuvan_1-1755442267205.png

var gr = new GlideRecord('alm_hardware');
gr.addQuery('sys_id','=','00a96c0d3790200044e0bfc8bcbe5dc3');
gr.query();
while (gr.next()) {
var gdpt = new GlideDateTime(gr.purchase_date);
var gdit = new GlideDateTime(gr.install_date);
var duration = GlideDateTime.subtract(gdpt, gdit);
duration=duration.getNumericValue()/86400000;
gs.print(Math.floor(duration));
}

 

If this helped to answer your query please mark my posts helpful & accept the solution to close the thread.

 

Thanks,

Bhuvan

View solution in original post

6 REPLIES 6

LouisRRonzi
Tera Guru

That could also work.  I think the field would have to be an integer field since we are wanting the number of 'Days' (e.g., 5, 40, 17). 

@LouisRRonzi 

 

Same logic can be extended as below if you want to store duration as integer,

Bhuvan_0-1755442242206.pngBhuvan_1-1755442267205.png

var gr = new GlideRecord('alm_hardware');
gr.addQuery('sys_id','=','00a96c0d3790200044e0bfc8bcbe5dc3');
gr.query();
while (gr.next()) {
var gdpt = new GlideDateTime(gr.purchase_date);
var gdit = new GlideDateTime(gr.install_date);
var duration = GlideDateTime.subtract(gdpt, gdit);
duration=duration.getNumericValue()/86400000;
gs.print(Math.floor(duration));
}

 

If this helped to answer your query please mark my posts helpful & accept the solution to close the thread.

 

Thanks,

Bhuvan