Skip to main content

Notifications

Announcements

No record found.

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 217

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,321 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);
    }

  • martinarul Profile Picture
    martinarul 217 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

  • martinarul Profile Picture
    martinarul 217 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

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,646 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);
    
    }

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 231,321 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.

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

Product updates

Dynamics 365 release plans