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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Cannot implicitly convert from type 'str' to type 'date'.

(0) ShareShare
ReportReport
Posted on by 123
 CASE WHEN (MONTH(salestable.CREATEDDATETIME)) <= 3 
                        THEN convert(varchar(4), YEAR(salestable.CREATEDDATETIME)-1) + '-' + convert(varchar(4), YEAR(salestable.CREATEDDATETIME)%100)    
                        ELSE convert(varchar(4),YEAR(salestable.CREATEDDATETIME))+ '-' + convert(varchar(4),(YEAR(salestable.CREATEDDATETIME)%100)+1)END AS Fiscal_Year,
__________________________________________________________________________________________________________________________
 
public void postLoad()
    {
        super();
        this.ConfirmedSOdate = DateTimeUtil::date(this.CreatedDateTime);
       
        if(mthOfYr(this.ConfirmedSOdate)<=3)
        {
            this.FiscalYear = strFmt(/%1-%2/,(Year(this.ConfirmedSOdate)-1), (Year(this.ConfirmedSOdate) mod 100));
        }
        else
        {
            this.FiscalYear = strFmt(/%1-%2/,(Year(this.ConfirmedSOdate)-1), (Year(this.ConfirmedSOdate) mod 100)+1);
        }
I have the same question (0)
  • Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    Cannot implicitly convert from type 'str' to type 'date'.
    Please give us more information. Where did you get the error mentioned in the title? When compiling your X++ code? If so, at which line?

    My assumption is that FiscalYear is a number and you get an error when you're trying to insert a string there. If so, you need to either use a string field, or to provide a numeric value instead of a string.
     
    I guess we should ignore the first code snippet, but it's hard to say when give no description of your problem.
     
    You'll have a better chance to get an answer if you tell us all you know right away.
  • M_R Profile Picture
    123 on at
    Cannot implicitly convert from type 'str' to type 'date'.
    I am creating data entity for sql code
     
     
    select 
         custtable.CUSTGROUP [sales type],
         salestable.SALESSTATUS [Order Status],
         convert(date,salestable.CREATEDDATETIME)  [Date],
         CASE WHEN (MONTH(salestable.CREATEDDATETIME)) <= 3 
                            THEN convert(varchar(4), YEAR(salestable.CREATEDDATETIME)-1) + '-' + convert(varchar(4), YEAR(salestable.CREATEDDATETIME)%100)    
                            ELSE convert(varchar(4),YEAR(salestable.CREATEDDATETIME))+ '-' + convert(varchar(4),(YEAR(salestable.CREATEDDATETIME)%100)+1)END AS Fiscal_Year,
     
     
    for that created 2 unmapped field fiscal year and confirmsodate as date

    is it the error for extended data type

  • Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    Cannot implicitly convert from type 'str' to type 'date'.
    Please confirm that you're getting a compilation error and that is on the assignment of FiscalYear field. Then read my previous reply to see your two option.
     
    I guess you used a wrong type of FiscalYear field.

    Also note that you could generate your SQL code with a computed column (but creating a virtual field is much easier, so it's probably a better option for you at the moment).
  • Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    Cannot implicitly convert from type 'str' to type 'date'.
    By the way, I would remove remove the duplication from your code with something like this:
    public void postLoad()
    {
        super();
        
        this.ConfirmedSOdate = DateTimeUtil::date(this.CreatedDateTime);
       
        int confirmYear = year(this.ConfirmedSOdate);
        
        if (mthOfYr(this.ConfirmedSOdate) <= 3)
        {
            confirmYear--;
        }
        
        this.FiscalYear = strFmt("%1-%2" , confirmYear, (confirmYear mod 100) + 1);
    }
    This also determines the first part of the "else" case according to the SQL code (your X++ decreases it by one).

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 701 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 588 Most Valuable Professional

#3
Sumit Singh Profile Picture

Sumit Singh 544

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans