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

Announcements

No record found.

News and Announcements icon
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 (1)
  • nmaenpaa Profile Picture
    101,166 Moderator on at

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

  • Martin Dráb Profile Picture
    239,040 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,166 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
    239,040 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
    239,040 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,166 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans