get number of days between 2 dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 01:07 AM
I have 2 dates in on form and calculated field. i have to get number of days between 2 dates. I wrote a script but its returning 20 days. I need only the count not 'days' word. Can anyone help me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 01:25 AM
Hi,
This community post might help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 01:31 AM - edited ‎03-24-2023 01:34 AM
Hi @Hareesha ,
You can use getDayPart() or getRoundedDayPart() methods , to get only the days part without "days" string. Try running the following script to understand this better.
var present = new GlideDateTime();
gs.print(present);
var future = new GlideDateTime();
future.addDaysUTC(1000);
gs.print(future);
var dur = GlideDateTime.subtract(present, future);
gs.print(dur);
gs.print(dur.getDayPart());
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 01:31 AM
Please share your script here.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader