Date should be added to next month according to period length

Dear User,

I have make one table in that i’m using period length and in another table i have used start date and end date now if i give period length 5 and select the start date as for example 01-09-14 so when i click on this it should change to 06-09-14 this is not the issue i have written code for this on validate of start date

RecTask.RESET;

RecTask.SETRANGE(RecTask.“No.”,“Document No.”);

IF RecTask.FIND(’-’) THEN BEGIN REPEAT

Day := RecTask.“Period Length” + DATE2DMY(“Start Date”,1);

Month := DATE2DMY(“Start Date”,2);

Year := DATE2DMY(“Start Date”,3);

“End Date” := DMY2DATE(Day,Month,Year);

MODIFY;

UNTIL RecTask.NEXT=0;

//MESSAGE(’%1/%2/%3’,Day,Month,Year);

END;

now the issue is if give period length for same document no like 28 it gives error

so it should be added to next month like 5 (periodl ength) + start date (28-09-2014 ) = End date(0308-2014). please help me out with the solution.

so it should be added to next month like 5 (periodl ength) + start date (28-09-2014 ) = End date(03-10-2014). please help me out with the solution.

Have you tried using the CALCDATE function? It’s quite versatile.

Hi,

A small Confirmation if you give 28 in period length then how can it calculates the date to be next 5 days…

Use this code

//Make Period length variable as Text

RecTask.RESET;

RecTask.SETRANGE(RecTask.“No.”,“Document No.”);

IF RecTask.FIND(’-’) THEN BEGIN REPEAT

Day :=STRLEN(RecTask.“Period Length”);

Expr :=INSSTR(RecTask.“Period Length”,‘D’,Day+1) //declare Expr as text variable

“End Date” := CALCDATE(Expr,“Start Date”);

MODIFY;

UNTIL RecTask.NEXT=0;

//MESSAGE(’%1/%2/%3’,Day,Month,Year);

END;

CALCDATE operates on a given date, and computes a new date based on the value of the date expression. It’s in the date expression that you specify the period (Unit = D, M, Y, etc.) and the integer representing the number of periods. From you question, I take it that the period is days, and the number of days is 5. In that case, you make the command CALCDATE(’<+5D>’, TODAY) to determine the date of the day that’s 5 days from today. I’m not sure how your value of 28 plays into the discussion.

Rather than spending more time describing what you’re doing, let’s talk a bit about what you’re trying to accomplish. We know you’re trying to calculate future date values. What’s the business case for that process? What do the system users need this feature to do for them?

Dear Uppala,

it calculates date according to start date in table 2 if period length is suppose 27 and if we give 050914 as starting date in another table automatically end date should changed to next month of 020914…

Dear Uppala,

it calculates date according to start date in table 2 if period length is suppose 27 and if we give 050914 as starting date in another table automatically end date should changed to next month of 020914…i’m trying the above code & will let u know the solution thanks.

Dear George,

no i didn’t try the CALCDATE function will try both of the above codes & let u know if its working or not thanks for the reply both of u…[:)]

Dear Abuzar,

It will work based on your requirement only if you give period length as 27 and starting date as 050914 then it will definitely calculates the end date as 021014 try that code once and let me know if it is not work…

Thanks

Dear George,

what i’m trying to do is i have given some work that i have to 3 table,in table 1 i have to take three field 1 No. from no.series 2 description should be manually added and third field period length now in second table 1 no from another no series 2 item no from item 3 item description from item 4 document no is table1 no. 5 description is tables1 description 6 start date 7 end date and in third table 1 document no. is tables 2 no line no from no series 3 item no from item 4 quantity should be added manually 5 no of days.

now the thing is if i give period length suppose 7 in table 1 so when enter details of table 2 start date suppose i give 10-09-2014 for the particular document no so end date should automatically change to 17-09-2014 and in table 3 for that particular document no 7 lines should be generated automatically according to period length. this is not the issue i have created every thing but only problem is when i give period beyond that particular month it shows error date is not getting added to next month.

Dear Uppala,

Thank you So much the code u have provided worked perfectly and its also generating lines as per the period date[:)] [:)].

hey can you explain me the code that u have given me…actually i want to know for future use please.[:P]

Thanks & Regards

Abuzar

Ya sure…

Nothing Great in that code Abuzar i just used CALCDATE function correctly thats all…

Abuzar,

The best way to learn how the CALCDATE function works is to experiment with it. Build yourself a page that has various CALCDATE expressions and then observe the effect. It’s always nice to test near the edges, so I usually like to use Feb 25 of a leap year, or Dec 30 as a starting date. If you’re going to get strange results, this would be one of the best places to see that.

As for the code, you may like to simplify a bit …

“End Date” := CALCDATE( strsubstno(’<+%1D>’, “Period Length”), “Start Date”);

This works well if “Period Length” is always related to Days. If it’s something other, then you’d need another field in your TASK-A lookup table to indicate the Period Type. And, this way, you can define “Period Length” as an integer instead of text. Definitely helps with data input validation.

Dear george,

Thank you for the wonderful explanation regarding CALCDATE function.