web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

date difference is not accurate

(0) ShareShare
ReportReport
Posted on by 110
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)))
I have the same question (0)
  • Martin Dráb Profile Picture
    236,258 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,257

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 913 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 611 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans