Date functions in AX2012

    Different  types of date functions that are available in ax2012.

static void Datefunctions(Args _args)

{


    str          s;

    int          i,noOfMonths,noOfMonthsBetweenYears;

    date         c;

    Date         dob;

    Date         _LastDateOfMonth;

    Int          month_number;

    Int          years_numbers;

    Int          day_number;

    TransDate    d1,d2;

    date         d3 =18\04\1998;

    date         d4 = 17\8\2020;

    int          daydiff,yrdiff,monthdiff;

    date         inputDate = str2Date("4/18/1998", 213);

    date         refDate = str2Date("8/17/2020", 213);

    TransDate    k,    now = today();

    date         maximumdate;

    //Gives name of day

    s= dayName(12);

    info(strFmt(" day  is %1",s));



    //Gives Date

    i=dayOfMth(today());

    info(strFmt('todays date of the month is %1',i));



    //Gives Day no of a week

    i=dayofwk(today());

    info(strFmt('todays day of the week is %1',i));


    i=dayOfYr(today());

    //info(strFmt('todays day of the year is %1',i));

    info(strFmt( 'todays day of year is ' +int2str(i)));


    i=wkOfYr(today());

    info(strFmt('todays week of a year is' +int2str(i)));


    i=year(30\05\2098);

    info(strFmt(' year is' +int2str(i)));



    //mkdate

    Day_number=18;

    Month_number=4 ;

    years_numbers=1998;

    dob =mkdate(Day_number, Month_number, years_numbers);

    info(strFmt('%1',dob));


    //name of month

    s=mthName(11);

    info(s);


    //next month

    c=nextMth(today());

    info(strFmt('%1',c));

    c=nextMth(22\12\2020);

    info(strFmt('%1',c));


     //previous month

    c = prevMth(today());

    info(strFmt("%1",c));




    //quater

    c=nextqtr(1\1\2020);

    info(strFmt('%1',c));

    c=nextqtr(today());

    info(strFmt('%1',c));


    //prevqtr

    c = prevqtr(17\1\2020);

    info(strFmt("%1",c));




    //next year

    c = nextYr(today());

    info(strFmt("%1",c));


    // prev year

    c= prevyr(8\6\2019);

    info(strFmt("%1",c));



    //today

     c= today();

     info(strFmt("%1",c));


    //timenow

    i= timeNow();

    info(strFmt("%1",i));


    c=dateEndWk(Today());

    info(strFmt("%1",C));

    C=dateStartWk(today());

    info(strFmt("%1",C));


    //date start and end of years and month

    c = dateStartMth(today());

    info(strFmt("%1", c));

    c=dateEndMth(today());

    info(strFmt("%1", c));

    C=dateStartYr(today());

    info(strFmt("%1", c));

    c=dateEndYr(today());

    info(strFmt("%1", c));


    //fowrd & bckwrd months

    C=today();

    info(strFmt('%1',dateMthFwd(systemdateget(),5)));

    C=today();

    info(strFmt('%1',dateMthFwd(systemdateget(),-5)));

    //DateDifference

    d1  = 16\8\2021;

    d2  = today();

    i = d2 - d1;

    info(strfmt("%1",i));

    daydiff=dayOfMth(d4)-dayOfMth(d3);

    yrdiff=year(d4)-year(d3);

    monthdiff=mthOfYr(d4)-mthOfYr(d3);

    info(strFmt("%1",daydiff));

    info(strFmt("%1",yrdiff));

    info(strFmt("%1",monthdiff));


    //months dif btwn years

    noOfMonths = intvNo(refDate, inputDate, intvScale::Month);

    noOfMonthsBetweenYears = intvNo(refDate, inputDate, intvScale::YearMonth);

    info("noOfMonths  :"+int2str(noOfMonths) + "  ,noOfMonthsBetweenYears  :"+int2str(noOfMonthsBetweenYears));


      k = DateTimeUtil::Date(DateTimeUtil::addMonths(DateTimeUtil::newDateTime(now, 0, DateTimeUtil::getCompanyTimeZone()),-6));

       info(strFmt("%1",k));

    maximumdate=maxDate();

    info(strFmt("%1",maximumdate));

}


No comments:

Post a Comment