Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Getting wrong date and time

(0) ShareShare
ReportReport
Posted on by 2,129

Hello Experts,

I have a display method under table CustInvoiceJour.

In method I used code like below:

utcDateTime Timestamp;
str Timestamp1;
Timestamp=this.createdDateTime;
Timestamp1=datetime2str(Timestamp);

and finally added Timestamp1 to QR code.When I check entry in under Inquiry form like below Date and Time is correct.

8171.T1.jpg

But in QR code information Date is correct but Time is not correct.

QR_5F00_Code_5F00_Info.jpg

Thanks,

Faiz

  • Verified answer
    Martin Dráb Profile Picture
    231,884 Most Valuable Professional on at
    RE: Getting wrong date and time

    I don't think you really want to hard-code the timezone in code. Most likely, you want the timezone configured for the current user:

    DateTimeUtil::applyTimeZoneOffset(timestamp, DateTimeUtil::getUserPreferredTimeZone()));

    Alternatively you might want the timezone of the current company.

  • faiz7049 Profile Picture
    2,129 on at
    RE: Getting wrong date and time

    Hi Martin,

    Sorry I did not know before. How to apply like

    utcDateTime Timestamp, Timestamp2;
    str Timestamp1;
    Timestamp=this.createdDateTime;
    Timestamp2= DateTimeUtil::applyTimeZoneOffset(Timestamp,UTC 03:00);
    Timestamp1=datetime2str(Timestamp2);

    Please guide me if you do not mind.

    Thanks,

    Faiz

  • Suggested answer
    Martin Dráb Profile Picture
    231,884 Most Valuable Professional on at
    RE: Getting wrong date and time

    You forgot to apply user's timezone.

    Datetime values are stored in UTC in database. They're automatically convert to user's timezone in forms, but it's your responsibility in your code.

    Use DateTimeUtil::applyTimeZoneOffset().

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,884 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans