Days between computer purchase date and install date

Louis R Ronzitt
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

@Louis R Ronzitt 

 

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

Bhuvan
Kilo Patron

@Louis R Ronzitt 

 

Purchase date field is of type 'date' and Install date is of type 'date/time'. You can use GlideDateTime to calculate the number of days between purchase date and install date.

 

For example, below is a sample record from alm_hardware table. Use below code to calculate the duration between purchase date and install date. This is only for reference and you can enhance as per your requirements.

 

Bhuvan_0-1755309111108.png

Bhuvan_4-1755309155443.png

Bhuvan_5-1755309209428.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); 
gs.print(duration.getDisplayValue());
}

 

If this helped to answer your query, please accept the solution and close the thread.

 

Thanks,

Bhuvan

 

Bhuvan
Kilo Patron

@Louis R Ronzitt 

 

If the comparison fields are of same type, you can use 'Configure function field' in report and calculate the duration in runtime.

 

For example, below is a duration between incident resolution and creation calculated using function field.


Bhuvan_0-1755311105407.png

Bhuvan_1-1755311149259.png

 

If this helped to answer your query, please accept the solution and close the thread.

 

Thanks,

Bhuvan

Louis R Ronzitt
Tera Guru

Both helpful. In the alm_hardware table, I think I'd need a calculated field of some sort, though, since that table doesn't include a 'time to resolve' field. So, I'm looking for something similar to the 'Time to resolve' field in the incident table example. I'd need to show an integer in a column so I can report on each record with one column (purchase_date), the next column (install_date), and the third column, the 'Days' between.

 

@Louis R Ronzitt 

 

If you are looking to create a field to store the duration between purchase and install dates, you can create a date or date/time data type field and can use the same GlideDateTime logic in Business Rule.

 

If my posts helped to guide you or answer your query, please accept the solution and close the thread.

 

Thanks,

Bhuvan