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, ...
Answered

view computed column to get the Month and Year from the CreatedDateTime field

(0) ShareShare
ReportReport
Posted on by 223

Dear Friends,

 I want to add two view computed column to get the month and year from the CreatedDateTime field in ax 2012 R3.

Can someone suggest the sample code?

Regards

Martin

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: view computed column to get the Month and Year from the CreatedDateTime field

    T-SQL has MONTH() and YEAR() functions for this purpose.

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at
    RE: view computed column to get the Month and Year from the CreatedDateTime field

    Hi Martin,

    In order to achieve what you want, you can use below code:

    public void Date()
    {
        date createdDateTime;
        ;
    
        createdDateTime = DateTimeUtil::date(this.createdDateTime);
    
        this.Month = mthofyr(createdDateTime);
        this.Day = dayofmth(createdDateTime);
        this.Year = year(createdDateTime);
    
    }

  • martinarul Profile Picture
    223 on at
    RE: view computed column to get the Month and Year from the CreatedDateTime field

    Hi Martin,

     I am aware that Month() and Year() function is available in sql. My doubt is how add computed column for month and year in AOT view. Please suggest the sample code

    Regards

    Martin

  • martinarul Profile Picture
    223 on at
    RE: view computed column to get the Month and Year from the CreatedDateTime field

    Hello Hossein,

     I am aware of this code. My concern is how to create a computed column for Month and Year in AOT View from CreatedDateTime field.

    Regards

    Martin

  • Verified answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: view computed column to get the Month and Year from the CreatedDateTime field

    If you know which T-SQL functions you should use, then what exactly do you need from us? Does it mean that you don't know how to write computed columns at all and you're looking for an introduction, or do you have any particular problem?

    Maybe seeing a code example will help you:

    private static str yearSql()
    {
    	str fieldIdent = SysComputedColumn::returnField(tableStr(YourView), identifierStr(DsName), fieldStr(YourTable, YourField));
    	return strFmt('YEAR(%1)'), fieldIdent);
    }

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,004

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 548 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans