Показать сообщение отдельно
Старый 27.05.2008, 14:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
palleagermark: Transform a date into a number of months from a specific offset date
Источник: http://palleagermark.blogspot.com/20...of-months.html
==============

Here is a small algorithm to transform a date into a number of months from a base date. You can for example use this if you need to create a report with numbers places in a column per month starting with the month of a specific date.

The algorithm to transform the date into a month is this:
X++:
if (columDate < dateEndYr(offSetDate)) 
{ 
    column = mthOfYr(columDate) - mthOfYr(offSetDate) + 1; 
} 
else 
{ 
    column = 12 - mthOfYr(offSetDate) + mthOfYr(columDate) +1; 
}
And here is a job to illustrate the useage:
X++:
static void date2Column(Args _args)
{ 
    Date offsetdate; 
    Date columDate; 
    int column; 
    int counter; 
;

    offSetDate = 30\09\2008; 
    columDate = offSetDate;
    while (counter <= 11) 
    { 
        counter++;
        // The actual algorithm --> 
        if (columDate < dateEndYr(offSetDate)) 
        { 
            column = mthOfYr(columDate) - mthOfYr(offSetDate) + 1; 
        } 
        else 
        { 
            column = 12 - mthOfYr(offSetDate) + mthOfYr(columDate) +1; 
        } 
        // The actual algorithm <--
        print strFmt("Date: %1 Month: %2", columDate, column); 
        columDate = dateMthFwd(columDate, 1); 
    } 
    pause;
}
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.