Getting first day of current period

I want to know how to get the start date of current period. For example, we know that TODAY=071302. How do I arrive at the start date of this period as 070102? Thanks. Pari Somasundaram.

This code gives you the starting date of the current week. You can use other periods by changing the filter on “Period Type”. recDate is a variable of datatype Record and subtype Date. recDate.RESET; recDate.SETFILTER(“Period Type”,’%1’,recDate.“Period Type”::Week); recDate.SETFILTER(“Period Start”,’<=%1’,TODAY); recDate.SETFILTER(“Period End”,’>=%1’,TODAY); IF recDate.FIND(’-’) THEN MESSAGE(‘Starting date of current week is %1’,recDate.“Period Start”); Good luck

recDate.RESET; recDate.SETFILTER(“Period Type”,’%1’,recDate.“Period Type”::Week); recDate.SETrange(“Period Start”,0d, workdate); recDate.FIND(’+’); MESSAGE(‘Starting date of current week is %1’,recDate.“Period Start”);

I may be wrong, [img]/forum/images/icon_smile_shock.gif" border=“0”> but I think that Pari is trying to find the first day of the current accounting period.

with AccountingPeriod do begin
  RESET;
  SETFILTER("Starting Date",'<=%1',TODAY);
  IF FIND('+') THEN
    MESSAGE('Starting date of current period is %1',"Start Date");
end;

_________________________ David Singleton Navision Consultant since 1991 [u]dm Edited by - David Singleton on 2002 Jul 14 19:56:54

hi friend… startdate := CALCDATE('CM+1D-1M ',Date); will do… check it… is it ok Lakshmi Valluru

If Pari is in fact trying to calculate the starting date of an accounting period then I believe David’s solution is the only correct one. Lakshmi’s will work only if the accounting periods match the calender months, which is not necessarily the case. Kind regards, Jan Hoek

Unfortunately, no it does not work. It would if your accounting periods = calendar months, but it deos not solve the actual question asked. In any case, if you want to find the first day of the month, the correct synax is:

startdate := CALCDATE('-CM',Date);

_________________________ David Singleton Navision Consultant since 1991 dmks22@comcast.net___________

Thank you all for your suggestions. I think I have the answer. Pari Somasundaram.

I am using NAV 2009 (version 6x)

I need to find the values in the Customer flowfields using the Date Filter for the current period.

I have looked at the suggestions above but cannot get any values.

For a start there is just the “Starting Date” now.

From the Sales Line I am trying the following without any success:

CheckContractLimit(VSellToCustCode : Code[20])
VCust.GET(VSellToCustCode);
WITH AccountingPeriod DO BEGIN
RESET;
SETFILTER(“Starting Date”,’<=%1’,TODAY);
IF FIND(’+’) THEN
sDate := “Starting Date”;
SETFILTER(“Starting Date”,’>=%1’,TODAY);
IF FIND(’+’) THEN
eDate := “Starting Date”;
END;
VCust.SETRANGE(“Date Filter”,sDate,eDate);
VCust.CALCFIELDS(“Invoiced Contract Value”,“Ordered Contract Value”,“Contract Price (Maximum)”);

I get no value in the sDate or eDate vars

What am I missing?

Cheers,

Colin

Hi,

Using your above code I am getting proper value for sDate & eDate. I tried following code in a new codeunit and getting result:

WITH AccountingPeriod DO BEGIN
RESET;
SETFILTER(“Starting Date”,’<=%1’,TODAY);
IF FIND(’+’) THEN
sDate := “Starting Date”;
SETFILTER(“Starting Date”,’>=%1’,TODAY);
IF FIND(’+’) THEN
eDate := “Starting Date”;
END;
MESSAGE(’%1…%2’,sDate,eDate);

Edited later: Instead of saying proper values, I should write that I am getting value, whcih is starting date of current period and starting date of last period in Accounting Period table.

So am I now since I changed the Record variable to the correct table “Accounting Periods GB”.[:$]

Silly mistake.

I needed to add NORMALDATE(eDate).

Thanks,

Colin