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

Announcements

News and Announcements icon
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

    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,079 on at

    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

    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

    Hi Rudi,

    Thanks ..its working perfectly....

    thanks a lot

  • Michael N Profile Picture
    140 on at

    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

    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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 10

#2
Harisgillani Profile Picture

Harisgillani 4

#2
dserp Profile Picture

dserp 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans