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

Converting Date and Time field to to hours

Kaleem A
Giga Guru

Hi All,

I have a script

var actualDateTime = new GlideDateTime();

actualDateTime.setDisplayValue(gs.nowDateTime());

var gr = new GlideRecord('change_request');

gr.addQuery('number','CNGXXXXXXX')

//gr.addQuery('approval','requested');

//gr.addQuery('state','IN','1,2');

gr.query();

gs.print(gr.getRowCount());

if (gr.next()){

var impendTime = gr.end_date;

var dur = gs.dateDiff(impendTime, actualDateTime);

var d = dur.getMinutes();

gs.print(impendTime);

gs.print(actualDateTime);

gs.print(dur);

}

I get dur   out put in Day HH:MM:SS format. How do I convert   dur format to Hours or minutes? Can someone help me with this.

3 REPLIES 3

Harsh Vardhan
Giga Patron

Hi



are you looking your output like below screenshot?


find_real_file.png


Hi Harsh,



My requirement is if I get dur result as   "1 10:00:00". I want to convert this entire duration in to hours that is 24+10+00=34 Hours.


Check out the `max_unit` dictionary attribute. If you set `max_unit=hours`, you'll see what you want to see.



Docs: Set a duration field value