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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Convert time period to Y:M:D format x++

(0) ShareShare
ReportReport
Posted on by 70

Hi all,

I have a requirement in which I need to display a time period calculated to a format like this Y:10 M:5 D:20.

For example if I calculate an employee's service time and it is 10 years then I want to show this period like this (Y:10 M:2 D:18)

Is there any function in x++ to do this ?

Please, help me if any one knows something about it

Regards,

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at

    In what format do you have the employee's service time right now?

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Which versionn are you talking about? You've attached tags for both D365 and AX 2012.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Anyway, let's assume you used DateTimeUtil::getDifference to get difference of two date times.

    Then you have the difference in seconds.

    It's trivial to transform the difference to days: seconds DIV 86400 (86400 is the nr of seconds in a day).

    But the next steps are not so easy, and actually not even possible if you only have the difference.

    The exact number of years, months and days depends on leap years and the length of different months.

    In order to know them, you need to keep the employment start date and end date in your calculations all the time. There might be some libraries to get the result.

    Here's some discussion on how to do it in C#.

  • Dynamics365 Profile Picture
    70 on at

    sorry for not mentioning

    I'm using D365

  • Dynamics365 Profile Picture
    70 on at

    UTCDateTime

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    UTCDateTime contains a date, such as 7/12/2020, not a time span such as 10 years.

  • Dynamics365 Profile Picture
    70 on at

    Martin, is there a way to achieve what I explained earlier?

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Sure, it is. But we can't tell you details about what you should do until you explain what you use as the input.

  • Dynamics365 Profile Picture
    70 on at

    What I'm doing is, I'm getting the WorkerStartDate value in a temp table with field HcmEmploymentValidFrom.

    Then in the report design, I'm using expression  DateDiff("YYYY",Fields!HcmEmploymentValidFrom.Value,Now()).

    and It return the date difference like 10 , 5 or 6 years.

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi KZOo,

    thanks for the information.

    And do you want to show on your report just the nr of years? Or years, months and days as you wrote before?

    As mentioned, it can be a bit tricky because of leap years, different lengths of months and so on. But if you need to show only full years it's simpler.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans