Code to get month and year

Dear All,

My Name Didik

Please Help me.

I have code to get the periode in month and year. But it doesnt work when the months are oct,nov and december (10,11 and 12). My Code doesn’t work when month after september.

when I debug this code, its always refer to jan (01/2013), but when its jan to sep (1 - 9) its run well.

this my code :

dialog = new dialog(‘Service Centre’);

dialogPeriode = dialog.addFieldValue(typeid(MonthYear), Periode, “Month/Year”);;
if (dialog.closedOk())
argsdialog = ‘’ ;
argsdialog = argsdialog + substr(‘0’ + int2str(mthofyr(periode)),strlen(‘0’ + int2str(mthofyr(periode)))-2,2) + int2str(year(periode));

how to fix this?

Hi Didik,

You are using Ax 2009 / Ax 2012 …?


Raman Kutala.

What result do you want to get? Wouldn’t be easier to use date2str()? E.g. date2str(periode, 123, DateDay::None, DateSeparator::None, DateMonth::Digits2, DateSeparator::None, DateYear::Digits4). Or if you need to convert it by yourself, num2str0() might help you too.

Dear Raman

Iam using AX 2009.

try below links…

hope this helps…

Oh God.

Why I dont think of this before.

thanks very much dear Martin.

Its done.