- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 05:54 AM
Hi All,
I have a requirement below:
Invoice billing amount : 300: start date: 01-11-2024, end date: 19-11-2024.
so here requirement is to calculate Invoice billing amount should calculate only for the days between start & end date are: 19/30*300=190.
but in script it is calculating only 18 days.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 06:49 AM
Hi @sainath3,
Whilst I salute the resistance to 'manually' add the additional day, the subtract method in both the GlideDate and GlideDateTime API will not factor in include the start date for example into the calculation.
Can you expand on the values you retrieve in 'invoice.u_start_date' fields? Are they dates or date time values?
I notice you're leveraging the 'getRoundedDayPart()' method which will round up if you are in fact handling date time values and the hours diff is over 12 hours (even 1 second over the 12 hours diff. IF it is exactly 12 hours, it will not round up).
Depending on whether you are handling date time values or just dates, you could simply ensure you only use the date value and use the GlideDate API to ensure hours are not taken into consideration and then always add one day.
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 06:49 AM
Hi @sainath3,
Whilst I salute the resistance to 'manually' add the additional day, the subtract method in both the GlideDate and GlideDateTime API will not factor in include the start date for example into the calculation.
Can you expand on the values you retrieve in 'invoice.u_start_date' fields? Are they dates or date time values?
I notice you're leveraging the 'getRoundedDayPart()' method which will round up if you are in fact handling date time values and the hours diff is over 12 hours (even 1 second over the 12 hours diff. IF it is exactly 12 hours, it will not round up).
Depending on whether you are handling date time values or just dates, you could simply ensure you only use the date value and use the GlideDate API to ensure hours are not taken into consideration and then always add one day.
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 08:37 PM
Hi Robbie,
Thanks for quick reply.
we are considering only dates not date & time.
even after removing "getRoundedDayPart()" method also getting same no of days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 01:32 AM
Hi @sainath3,
Thanks for confirming.
Just to be clear (as mentioned above), the the subtract method in both the GlideDate (and GlideDateTime) API is simply the difference and will not factor in or include the start date for example into the calculation.
Therefore you will need to plus 1. The reason why I asked if you were handling date objects or datetime objects was for the rounding aspect, but as thi is not required you can rest assured that by adding 1 will always be correct.
So - to simply answer your question. The subtract method is correct and working as designed. If you want to include the startdate into the calculate you need to plus 1.
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie