Calculate days between two dates in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 04:15 AM
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
Please help.
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 05:18 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 05:16 AM
Hi @Sowmya20 ,
If it is a catalog item you an create a onchange catalog client script to get the no of days.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 05:20 AM
Hi Pavan,
Thank you for the replay. Can you please provide sample code for to get the no of days
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 05:39 AM
Hi @Sowmya20 ,
is no of days single line text variable type?
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 05:43 AM
Yes Pavan