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 :
Microsoft Dynamics AX (Archived)

convertion of date time to string

(0) ShareShare
ReportReport
Posted on by

Hi guys,

how to convert date time : " 6/15/2009 1:45:30 PM" to  "2009-06-15T13:45:30.0900000" using x++

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: convertion of date time to string

    you should check out the DateTimeUtil class, it has several methods to manipulate date/time. Especially the DateTimeUtil::toFormattedStr method will help you out.

  • Verified answer
    Rudi Hansen Profile Picture
    4,069 on at
    RE: convertion of date time to string

    This code will print 2015-12-04T09:59:24, is that close enough?

    static void DateTest(Args _args)
    {
        UtcDateTime     dateTime = DateTimeUtil::getSystemDateTime();
        ;
        print DateTimeUtil::toStr(dateTime);
        pause;
    }
  • Community Member Profile Picture
    on at
    RE: convertion of date time to string

    Hi tom,

    i tried this ..but not working may be syntax problem.

    dateTimeUTC = DateTimeUtil::utcNow();

    regularTime1 = DateTimeUtil::toStr(dateTimeUTC );

  • Community Member Profile Picture
    on at
    RE: convertion of date time to string

    Hi Rudi,

    Thanks ..its working perfectly....

    thanks a lot

  • Michael N Profile Picture
    140 on at
    RE: convertion of date time to string

    Hi,


    if you need a special format, you can try System.DateTime.

    https://msdn.microsoft.com/en-us//library/8kb3ddd4%28v=vs.110%29.aspx


    static void SystemDateTime(Args _args) { UtcDateTime dateTime = DateTimeUtil::getSystemDateTime(); System.DateTime sysDateTime; ; sysDateTime = dateTime; print sysDateTime.ToString("yyyy-MM-dd"); print sysDateTime.ToString("MM/dd/yy H:mm:ss zzz"); pause; }


    Michael

  • ismaelivan Profile Picture
    578 on at
    RE: convertion of date time to string

    Thanks Rudi Hansen,

    I was looking to convert a date field to string format "2018-04-11T14:26:04"

    utcdatetime datetime1 = DateTimeUtil::applyTimeZoneOffset(
    DateTimeUtil::newDateTime(MYDATEFIELD, 0),
    DateTimeUtil::getClientMachineTimeZone());

    DateTimeUtil::toStr(datetime1)

    Thanks

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans