Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

str2Date() function is not working when trying to convert string to date.

Posted on by Microsoft Employee

hi,

im trying to convert string to date. i am extracting a date value from a form using ActiveDate.valueStr() and storing this into a string var. i have put this into a container, converted the container into a string using con2str() and attached it to args, args.parm(strcon). i am passing this through an action menu item, and when i receive the value there through the same args.parm(), i am converting the string back to container and using conpeek() to extract the value. i am storing the extracted value back into a string. now i have created an edt called activeDate which is of type date and creating an instance of that and using str2date(str,123) i am trying to store it back into the activeDate instance but its showing the default value of 1/1/1900. on debugging its only at this statement where its not converting it.

Categories:
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: str2Date() function is not working when trying to convert string to date.

    thank you. it worked.

  • Verified answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,786 on at
    RE: str2Date() function is not working when trying to convert string to date.

    You've certainly added some complexity there that probably has nothing to do with your str2date(..) problem.  Since you've already indicated that the date string obtained from ActiveDate.valueStr() survives "as is" all the way to str2Date, the problem must be there.

    The 2nd parameter you provided to str2Date(.., 123) indicates that the date format is day, month, year.  Is that the format returned by .valueStr() in your case?  It may (I have not tested it) depend on your localization settings, or those on the tier where the code is running (server?).

    Regardless, in a Date control's modified method, I am able to extract the .valueStr() in month/day/year format, and then convert it back to a Date type using str2Date(.., 213), where 213 means month/day/year.

    Perhaps instead of using .valueStr() which may not produce a predictable results across all users and environments, try extracting the .dateValue() and then using date2Str(..) to format it precisely according to how your str2Date(..) function will expect it.  The result should be more reliable and work as expected.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans