Calculate days between two dates in portal

Sowmya20
Tera Contributor

Hi,

 

I have requirement to display number of days between two dates in portal.

Example: Start Date :28-08-2023

                End Date: 30-08-2023

No.of Days need display: 3

Sowmya20_0-1692961979525.png

Please help.

Thanks,

Sowmya

11 REPLIES 11

Mohith Devatte
Tera Sage
Tera Sage

Hello @Sowmya20 ,

you can use this server script to calculate days 

var start = new GlideDateTime(''your_start_Date_field_name);
var end =new GlideDateTime('your_end_Date_field_name');
var dateDifferenceInMs =end.getNumericValue() - start.getNumericValue();
var dateDifferenceInDays = Math.floor(dateDifferenceInMs / (1000 * 60 * 60 * 24));
gs.info(dateDifferenceInDays);

 

Note :untested

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

Hi Mohith,

 

Thank you for the replay. But I need display the answer in Service Portal.

 

@Sowmya20 is this in a catalog item ?

Yes Mohith