Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to get server date using x++ code.

Posted on by 149

Hi Everyone,

A small request. How can I get server date using x++ code.

Thanks.

  • Suggested answer
    How to get server date using x++ code.
    systemDateGet: Retrieves the session date, if it has been set.
    Remarks: The today function returns the system date.
     
    What's more in "Modules > Common > Common > Session date and time" there is Current date which is non editable and Session date which is editable.
    I investigated the code used for changing session date in SystemDate form and method updateCurrentDateTimeValues():
    currentDate.dateValue(DateTimeUtil::getToday(preferredTz));
    currentTime.value(DateTimeUtil::getTimeNow(preferredTz));
    currentTimeZone.selection(preferredTz);
    
    sessionDate.dateValue(DateTimeUtil::date(sessiondatetime));
    sessionDate.value(DateTimeUtil::time(sessiondatetime));
    sessionTimeZone.selection(preferredTz);
    It seems that the non editable date of the System comes from getToday(TimeZone) method.
  • Suggested answer
    GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: How to get server date using x++ code.

    Hi Apratim,

    You can make use of DateTimeUtil class.

    DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

    Thanks,

    Girish S.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans