is there a way to format datediff to show days only

chennessy
Kilo Expert

here is the business rule I've found in the community, for a field called u_days

u_setDays();

function u_setDays() {

        var dte = gs.dateDiff(current.u_date_submitted.getDisplayValue(), current.u_date_accepted.getDisplayValue(); false);

        current.u_days = dte;

}

It's calculating the number of days correctly, but I need it to show days only, not     ddd   hh:mm:ss

How do I set the display to show days only?

Any suggestions are much appreciated!

1 ACCEPTED SOLUTION

JennyHu
Tera Guru
Tera Guru

Hi Cheryl,



You can return the difference between the dates to a GlideDuration object, and get the number of days from GlideDuration using getDayPart().  



u_setDays();


function u_setDays() {


      var dte= GlideDateTime.subtract(new GlideDateTime(current.u_date_submitted), new GlideDateTime(current.u_date_accepted));


      current.u_days = dte.getDayPart();


}


View solution in original post

8 REPLIES 8

Now the calculation is not working; it is giving me a '1' regardless of the dates.   Also, should u_days be of type Integer?  


What type of field is u_days currently?



It doesn't necessarily HAVE to be an integer field. It might be helpful.



If you want to do calculations against it (like differences, sums, etc.) then an integer is helpful. It also allows you to validate that you're not putting garbage data like strings "xxx" in the field.


JennyHu
Tera Guru
Tera Guru

Hi Cheryl,



You can return the difference between the dates to a GlideDuration object, and get the number of days from GlideDuration using getDayPart().  



u_setDays();


function u_setDays() {


      var dte= GlideDateTime.subtract(new GlideDateTime(current.u_date_submitted), new GlideDateTime(current.u_date_accepted));


      current.u_days = dte.getDayPart();


}


Jenny,


It worked!       Thank you!    


Thanks also to Chuck and Ankur, I am learning a lot here!