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

Community site session details

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

How to format DateTime to include AM/PM in output?

(1) ShareShare
ReportReport
Posted on by 374
Hi everyone,
I am trying to display a DateTime value for example: "ModifiedDateTime": "2025-06-30T19:51:59Z" in this format: 6/30/2025 07:51:59 PM. I used the code below to format it, but it doesn’t show AM/PM ! what am I missing?

  static static Str getFormatDateTime(utcDateTime _dateTime)
  {
        

      str formattedOutput;
 
      formattedOutput = DateTimeUtil::toFormattedStr( _dateTime,
      213,
      DateDay::Digits2,
      DateSeparator::Slash,
      DateMonth::Digits2,
      DateSeparator::Slash,
      DateYear::Digits4,
      TimeSeparator::Colon,
      TimeSeparator::Colon);
      
      return formattedOutput;
  }
 
I have the same question (0)
  • Yng Lih Profile Picture
    677 on at
    How to format DateTime to include AM/PM in output?
    Hi, 
     
    Please refer to  post, his reply is correct. :)
  • Martin Dráb Profile Picture
    235,412 Most Valuable Professional on at
    How to format DateTime to include AM/PM in output?
    @D365FO Junior-Dev I see you've verified Yng Lih's reply as a solution, but are you sure about it? As far as I know there is no static toString() method on DateTimeUtil class and no method accepting the .NET format string. Unless I'm missing something, the suggestion looks completely wrong to me.
  • Verified answer
    Yng Lih Profile Picture
    677 on at
    How to format DateTime to include AM/PM in output?
    Hi, updated the old posting..
     
    Please refer to   reply, which is correct. :)
     
     
  • Verified answer
    Martin Dráb Profile Picture
    235,412 Most Valuable Professional on at
    How to format DateTime to include AM/PM in output?
    Can't we make it much simpler? 
    System.DateTime dt = _dateTime;
    return dt.ToString('G');
    The result should be what you want if the current culture is en-us.
     
    Alternatively you can use the format M/d/yyyy hh:mm:ss tt.

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

#1
Alireza Eshaghzadeh Profile Picture

Alireza Eshaghzadeh 799 Super User 2025 Season 2

#2
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 757 Super User 2025 Season 2

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 751 Super User 2025 Season 2

Product updates

Dynamics 365 release plans