Compare two date fields & calculate days between the two?

Edwin Fuller
Tera Guru

I have a field called "Original Expected Completion Date" that is populated automatically when another field called "Expected Completion Date" is filled in by a user. I need to capture the number of days it took to populate the field by comparing the "Created" date field with the "Updated" date field. I already have a business rule script running on the "Expected Completion Date" field as well.

Any thoughts of how I could accomplish this, example scripts would be great.

Thanks,

Edwin

1 ACCEPTED SOLUTION

My bad.   Here you go. This is how you set a duration field.



Script:


var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());


var gdt2 = new GlideDateTime(gs.nowDateTime());


var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2


var dur1= new GlideDuration();


dur1.setValue(dur.getValue());


current.<name of duration field>=dur1.getDurationValue();


View solution in original post

10 REPLIES 10

Abhinay Erra
Giga Sage

Glad you got your question answered.