Skip to main content

Notifications

Announcements

No record found.

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

How to get server date using x++ code.

(0) ShareShare
ReportReport
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,816 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,433 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans