Tuesday, May 4, 2010

A Now() or GetDate() Method for AX

It should be noted, that after I made this post, it was revealed to me that the DateTimeUtil::utcNow() method accomplishes this goal...

Today I simply have a quick tip. I needed to be able to obtain the current date & time; something similar to the DateTime.Now() function in .NET or the getdate() function in SQL Server; However as far as I can tell, AX provides no quick function for this, so I wrote my own:


public utcdatetime Now()
{


str tDate;
str tTime;
utcdatetime utc3;


;


tDate = date2str(systemDateGet(), 321, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4);
tTime = time2Str(TimeNow(), TimeSeparator::Colon, TimeFormat::AMPM);
return str2datetime(tDate + " " + tTime, 321);


}

4 comments:

  1. how about this method :-)

    DateTimeUtil::utcNow();

    ReplyDelete
  2. TransDate TransDate=today();

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Sir,

    I am asking for your help. Do you have any idea how to insert new row in MS Excel using x++ code? :-) God Bless!

    Regards,

    AML

    ReplyDelete