System.datetime invoiceDateTime ; str newDateTime = date2Str(retailTransactionTable.transDate,321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2,DateSeparator::Hyphen,DateYear::Digits4) ' ' time2Str(retailTransactionTable.transTime,TimeSeparator::Colon, TimeSeparator::Colon); invoiceDateTime = str2Datetime(newDateTime, 321);
When I'm trying above code. I'm getting error.
Please advise.
Thank you Martin.
Try and will update.
Of course it is possible.
One approach is what you did with date2Str() and timeStr(). If you have a problem with it, you'll need to describe the problem. Saying that you're getting an error somewhere isn't very useful.
Another approach is using Format() function of System.String. For example:
utcDateTime transDateTime = DateTimeUtil::newDateTime( retailTransactionTable.TransDate, retailTransactionTable.TransTime); str formatted = System.String::Format('{0:yyyyMMdd HH:mm:ss}', transDateTime);
Thanks for providing the info Martin.
is it possible to achieve my requirement ? ( I have to achieve format yyyy-MM-dd hh:mm:ss )
for above I have date value ( retailtrasactiontable.transdate ) and time field (retailtrasactiontable.transtime )
Moved from Microsoft Dynamics AX Forum.
Yes, I see what you're doing - and I'm explaining why it's wrong. Even if use used str2Datetime() correctly, it's useless to you, because what you want is getting a string. You have data and time and you want to convert them to a string with a specific format.
str2Datetime() is for the opposite scenario - when you have information about date and time a string and you want to parse the string to an utcDateTime value.
I'm using latest D365 and VS 2019.
I'm passing date value in date2str() and getting string value ( using this function to achieve format as per requirement )
I'm passing above str value in str2Datetime() and getting datetime value (using this function to achieve datetime values)
I'm sorry, but I still don't see the information about your version of AX. Could you please cooperate a bit and provide this information, so we don't suggest solutions that can't be used in your version of AX?
According to your description, you want to get a string with with date and time converted to string in a specific format. Do you agree? If so, you agree that you want a string, not a utcDateTime value.
utcDateTime doesn't have any string format. A string format applies when you want to convert utcDateTime to a string.
My requirement is to getting date values as below format
Format : yyyy-MM-DD hh:mm:ss
so I'm passing date and required data in 'd' variable and again converting str to datetime ( in invoiceDateTime variable )
if above process is not correct way, how to achieve that format.
If your goal is to get a string, then your assignment of invoiceDateTime doesn't make sense, because this variable is for datetime values, not for strings. The result you want is in 'd' variable; there is no point in converting it back to utcDateTime, even if you implemented it correctly.
By the way, I'm still waiting for the information that you should have provided at the very beginning: a description of the error (error message, whether it's a compilation error or a runtime one, where it occurs) and your version of AX.
Hi Martin,
Thank you for responding.
I created one class, which is generating CSV file. in that one date field is there but I'm getting blank values and I'm using below function [date2str() for getting date as per requirement ( format 2020-09-14 17:14:11).
please advise what is wrong in below code.
str d; utcDateTime invoiceDateTime; d = date2Str(10\15\2023,321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2,DateSeparator::Hyphen,DateYear::Digits4);// ' ' time2Str(65850,TimeSeparator::Colon, TimeSeparator::Colon); invoiceDateTime = str2Datetime(d, 321); info(strFmt("%1",invoiceDateTime));
I guess you want something like this:
utcDateTime invoiceDateTime = DateTimeUtil::newDateTime( retailTransactionTable.TransDate, retailTransactionTable.TransTime, DateTimeUtil::getUserPreferredTimeZone());
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156