Extracting date from CreatedDateTime and creating three columns with date, year and month in a view

Hello all,

I created a view from two tables and only have field CreatedDateTime available for listing date. How could I extract the date from CreatedDateTime and how could I add three columns to the view with date, year and month.

Thank you very much in advance

Ergun Oezdamar

This code may help you…

static void createdDateTime(Args _args)


PurchTable purchTable;

TransDate getDate;

int days,months,years;


select firstonly purchTable;

getDate = DateTimeUtil::date(purchTable.createdDateTime);

days = dayofmth(getDate);

months = mthofyr(getDate);

years = year(getDate);

print getDate;

print days;

print months;

print years;



Hi Ergun oezdamar,

You cannot do using view.You need to write code(X++) to get date ,year,month from the createddate time .Other option is to create a table in which you can customize ur field so that table contains field for date ,year,month and insert data from that table(orginal table).Use the newly crated table in view.

Hi P.Ram,

thank you for your idea. I’m afraid when I create a new table with these fields and insert data from original table I would need to insert the data regularly having an updated table, wright? I will rather try to write or to find the right code.

Thank you very much
Ergun oezdamar

Hi Kranthi,
thank you very much for the code. Can I use this code to create columns in views and how could I that? Excuse me, I’m really new in Dynamics AX (2009) so I need every information.

Can I use methods or queries to add columns to an existing view?

Ergun Oezdamar

Hi Ergun oezdamar,

if u just need to show data mean use display method.

You cannot use them in a view as they are not the database(Table) fields…

Hey ergun,

In order to achieve what you want, you should modify the table that have the main information, and later you can modify your view so it may bring what you need.

You can store in the table the three fields that you wish to control, month, day and year and use the following code in the insert method so it may save the values for later retrieval.

public void insert()
date createdDateTime;


createdDateTime = DateTimeUtil::date(this.createdDateTime);

this.Month = mthofyr(createdDateTime);
this.Day = dayofmth(createdDateTime);
this.Year = year(createdDateTime);



After that, the new records inserted in the base will have the control that you need to have in your view.

Hi Daniel,

thank you very much. This is very helpful to me, because I’m really new to Dynamics AX. I don’t know the function of the different elements in AX. How they work together. So I try to gather information and to realize smaller steps. I want and have to learn Dynamics AX. I need your and the other guys’ support and I hope you will also help me in future when I will for sure face troubles in AX.

Many thanks also to Kranthi and P.Ram


Ergun Oezdamar