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’);

dialog.addGroup(‘Parameter’);
dialogPeriode = dialog.addFieldValue(typeid(MonthYear), Periode, “Month/Year”);

dialog.run();
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 …?

Regards,

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…

http://kollidynamics.blogspot.in/2011/08/date-functions-in-ax-2009.html

http://www.dynamics-blog.com/2011/07/get-day-month-and-year-from-date-in.html

http://tech.alirazazaidi.com/some-usefull-date-functions-in-dynamics-ax-x/

http://axhelper.blogspot.in/2010/12/add-value-to-year-in-date.html

hope this helps…

Oh God.

Why I dont think of this before.

thanks very much dear Martin.

Its done.