
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Same logic can be extended as below if you want to store duration as integer,
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
If this helped to answer your query, please accept the solution and close the thread.
Thanks,
Bhuvan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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