- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:07 AM - edited 11-06-2024 12:09 AM
Hi All,
We have an requirement where we have create a field call Days old and it will calculate Days old data based on below scenario.
Based on the daily scheduled job it will take
- Based on the daily scheduled job it will take current RUN date and time: This is when the report is created.
- Planned End date: This is the date something was supposed to be finished.
To find the Days Old:
- Look at the Current RUN date and time.
- Compare it to the Planned End date.
- Count how many days have passed between these two dates.
So, Days Old shows how many days have passed since the planned end date up to the current date and time when the report is made.
Example:
- Current RUN date and time: November 6, 2024.
- Planned End date: October 31, 2024.
To calculate the Days Old:
- Start with the Current RUN date: November 6, 2024.
- Compare it to the Planned End date: October 31, 2024.
- Count the days between these two dates.
From October 31 to November 6, there are 6 days.
So, the Days Old would be 6 days. This means it has been 6 days since the planned end date.
Can anyone help me on this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:25 AM
var current_date = new GlideDateTime(); // current date
var end_date = '2024-10-31 05:11:50'; // planned end date
var new_date = new GlideDateTime(end_date);
var difference = GlideDateTime.subtract(new_date,current_date);
var differenceInDays = difference.getNumericValue() / 86400000;
gs.info(parseInt(differenceInDays));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:28 AM
Hi Shruti,
Thank you for the quick reply, i will try this and let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:42 AM
Hi @Shruti ,
You code is working and display the correct data, but it display the data in decimal can we remove the decimal for example can we remove everything and display on 20 days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:45 AM
Hi , I have used parseInt in last line to remove decimal part. Can you try that
parseInt(differenceInDays)