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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Date conversion issue when using OleDBDataReder

(0) ShareShare
ReportReport
Posted on by

Hello All,

The current AX installation I am working on has a custom class built which reads an excel file using OleDBDataReader. Everything is pretty much working as expected with it, except there is a weird issue with a date field in the excel document.

 

In the class, we declare the trxDate variable to be a Date date type, we then use OleDBDataReader.get_Item() to set the trxDate variable to the proper field in excel.

 

Normally this works fine, but I have recieved a few files to import using this class where the date field has an apostrophe in front of the date (e.g. '10/31/2015). When this occours, AX throws an error that the "Error executing Code: Wrong Type of argument for the conversion function" at the line:

 

trxDate = OleDBDateReade.Get_Item(3);

 

 

However, the code continues to run and sets the trxDate variable to January first of the yeah 20xx where xx is the month value in the origional date.

 

So '10/31/2015 becomes 1/1/2010, '21/1/2011 becomes 1/1/2012, ect.

 

So my question is, how/why is AX taking the date value with an apostrophy in front of it and converting it totally different date?

 

 

Thank you,

 

Philo

*This post is locked for comments

I have the same question (0)
  • nunomaia Profile Picture
    25 Moderator on at

    The Excel file doesn't have the apostrophe? It’s common to add that sign to a Excel cell to force the cell value as text

  • Community Member Profile Picture
    on at

    I am sorry for the misunderstanding. The Excel file does have the apostrophe and AX seems to be reading it as a string and is having trouble using it for the trxDate variable, and the variable is declaired as a Date date type.

    My main question is why is AX converting '10/31/15 to 1/1/10 even after throwing an error.

  • Suggested answer
    Community Member Profile Picture
    on at

    1/1/1900 is the minimum date in AX, if you declare a date variable in AX and you don't assign anything in it, the default value will be 1/1/1900. Even the "datenull()" function returns 1/1/1900,

  • nunomaia Profile Picture
    25 Moderator on at

    Like Qureshi mentioned, you are reading the default value of date

  • Community Member Profile Picture
    on at

    How is 1/1/10 the default value of the date?

    "My main question is why is AX converting '10/31/15 to 1/1/10 even after throwing an error."

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans