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

@Sowmya20 then you need to write two on change client scripts .

one would be on start date and one would be on end date.

In both the client script call a script include and pass the value of start date and end date to script include.

Once you get start and end dates in script include use the script i gave above to get the date difference between two dates.

 

Return that difference to the client script and use g_form.setValue('your_days_field','answer_you_got from_script_include');

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

 

Pavankumar_1
Mega Patron

Hi @Sowmya20 ,

If it is a catalog item you an create a onchange catalog client script to get the no of days.

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Hi Pavan,

 

Thank you for the replay. Can you please provide sample code for to get the no of days

 

Thanks,

Sowmya

Hi @Sowmya20 ,

is no of days single line text variable type?

 

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Yes Pavan