Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

date difference is not accurate

(0) ShareShare
ReportReport
Posted on by 104
Hello guys,
 
  •  How to calculate the date difference between the employee joining and termination date i.e. employee join date is 3/08/2023 08:00:00:00 and the termination date is 24/08/2023 08:00:00:00 when I figure the difference in its result is 22 days but in x++ code return 21 days how can I handle this.
  •  if the employee joining date is 3/08/2023 08:00:00:00 and the termination date is 3/08/2023 06:00:00:00 is the same then x++ return date difference 0, while I want to pay him one day's salary. Please guide me on how to handle this.
  terminateDate = hcmEmployment.ValidTO;
int daysInLastMonth = dayOfMth(terminateDate);
                                
daysInLastMonth= daysInLastMonth - dayOfMth((DateTimeUtil::date(hcmEmployment.ValidFrom)))
  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    date difference is not accurate
    One problem with your code is that it doesn't support employment that spans more than a single calendar month. But you don't have to (and you even shouldn't) calculate it by yourself - use existing methods instead. For example, there is DateTimeUtil::getDifference() (returning the number of seconds, which you need to convert to days), or System.DateTime.Subtract (returning System.TimeSpan object, which has a property called Days).
     
    Your second example is wrong, because the length of the employment is negative.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans