Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
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.

*This post is locked for comments

  • 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,788 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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans