Logic in Starting and Ending Date calculation

thankeshthankesh Member Posts: 170
Hi Experts,

I have created "Starting Date" and "Ending Date" fields in "SalesTarget" table with a primary key "Target name". I need to validate those two fields. The validation should check these following conditions.

1. Starting date and Ending date can be same or different.

2. While we enter the new record for starting date field in the table, the starting date should not be within the range of previous starting date and ending date entered. The system should check for all the records in the table. The starting date should be lesser than the ending date.

For this, I have added the following code. But, I got failures in the result in some scenarios:

when I try to enter in out of range of starting and ending dates, the system does not allows to enter it.

Starting Date - OnValidate()

Date1 := "Starting Date";
Date2 := "Ending Date";

SalesTarget.RESET;
IF SalesTarget.FIND('-') THEN BEGIN
REPEAT
WHILE (Date1 <= Date2 )
DO BEGIN
IF (Date1 <> 0D) AND (Date1 >= SalesTarget."Starting Date") AND (Date1 <= SalesTarget."Ending Date") THEN
ERROR(Text002);
Date1 := CALCDATE('1D',Date1);
END;
UNTIL SalesTarget.NEXT= 0;
END;


SalesTarget.RESET;
IF SalesTarget.FIND('-') THEN BEGIN
REPEAT
IF ("Starting Date" < SalesTarget."Ending Date") THEN
ERROR(Text002);
UNTIL SalesTarget.NEXT = 0;
END;


Help pls :shock:
With warm regards,

Thankesh

***Learn to lead***

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Add the following code in end date on validate
    IF "Start Date" > "End Date" THEN
      ERROR('Ending date should be greater tham starting date');
    
    1. Starting date and Ending date can be same or different.
    i dont think it needs to be validated :-k
    when I try to enter in out of range of starting and ending dates, the system does not allows to enter it.
    In the first line i have entered starting date 010110 and ending date 311210
    in the second line i have entered starting date 010111 and ending date 311211

    it is allowing to take..what else you want?
  • thankeshthankesh Member Posts: 170
    when I try to enter in out of range of starting and ending dates, the system does not allows to enter it.
    In the first line i have entered starting date 010110 and ending date 311210
    in the second line i have entered starting date 010111 and ending date 311211

    it is allowing to take..what else you want?

    In the first line I have entered Starting date 01/01/01 and ending date 10/01/01
    In the second line I have entered starting date 15/01/01 and ending date 20/01/01
    In the third line I need to enter starting date 12/01/01 and ending date 14/01/01. (12/01/01 .. 14/01/01 is not within the range of first and second line starting and ending dates. But the system is giving error).
    With warm regards,

    Thankesh

    ***Learn to lead***
  • thankeshthankesh Member Posts: 170
    In the first line I have entered Starting date 01/01/01 and ending date 10/01/01
    In the second line I have entered starting date 15/01/01 and ending date 20/01/01
    In the third line I need to enter starting date 12/01/01 and ending date 14/01/01. (12/01/01 .. 14/01/01 is not within the range of first and second line starting and ending dates. But the system is giving error).

    I need this kind of validation as stated in the previous example. Pl help. :?:
    With warm regards,

    Thankesh

    ***Learn to lead***
  • thankeshthankesh Member Posts: 170
    Edited...


    Hi Mohana,

    How to achieve this :!:
    With warm regards,

    Thankesh

    ***Learn to lead***
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    edited 2011-02-18
    May i know why did you write this code?
    SalesTarget.RESET;
    IF SalesTarget.FIND('-') THEN BEGIN
    REPEAT
    IF ("Starting Date" < SalesTarget."Ending Date") THEN
    ERROR(Text002);
    UNTIL SalesTarget.NEXT = 0;
    

    you can try by commentiong this code..
  • MGM08MGM08 Member Posts: 41
    The system is giving error because of ur logic of

    SalesTarget.RESET;
    IF SalesTarget.FIND('-') THEN BEGIN
    REPEAT
    IF ("Starting Date" < SalesTarget."Ending Date") THEN
    ERROR(Text002);
    UNTIL SalesTarget.NEXT = 0;
    END;

    The date 12/01/01 is lesser then 20/01/01.

    U need not loop through all the dates just for that record u need to check the ending date..

    Please use mohana logic for this validation.
  • MGM08MGM08 Member Posts: 41

    or use


    SalesTarget.RESET;
    SalesTarget.setrange(Target name,target name);//
    IF SalesTarget.FIND('-') THEN BEGIN
    //REPEAT
    IF ("Starting Date" < SalesTarget."Ending Date") THEN
    ERROR(Text002);
    //UNTIL SalesTarget.NEXT = 0;
    END;
  • thankeshthankesh Member Posts: 170
    May i know why did you write this code?
    SalesTarget.RESET;
    IF SalesTarget.FIND('-') THEN BEGIN
    REPEAT
    IF ("Starting Date" < SalesTarget."Ending Date") THEN
    ERROR(Text002);
    UNTIL SalesTarget.NEXT = 0;
    

    you can try by commentiong this code..


    Hi Mohana,

    I have already tried by removing the above code. But, I did not get the exact result which I stated in the example.
    If I comment this code, the starting date field will allow all the dates that we enter into that field. I need the validation as per I stated in the previous example. :roll:
    With warm regards,

    Thankesh

    ***Learn to lead***
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Start Date - OnValidate()
    Date1 := "Start Date";
    
    SalesTarget.RESET;
    IF SalesTarget.FINDSET THEN
    REPEAT
      IF (Date1 <> 0D) AND (Date1 >= SalesTarget."Start Date") AND 
        (Date1 <= SalesTarget."End Date") THEN
        ERROR('hi');
    UNTIL SalesTarget.NEXT = 0;
    

    End Date - OnValidate()
    Date2 := "End Date";
    IF "Start Date" > "End Date" THEN
      ERROR('Ending date should be greater tham starting date');
    
    SalesTarget.RESET;
    IF SalesTarget.FINDSET THEN
    REPEAT
      IF (Date2 <> 0D) AND (Date2 >= SalesTarget."Start Date") AND
        (Date2 <= SalesTarget."End Date") THEN
        ERROR('hi2');
    UNTIL SalesTarget.NEXT = 0;
    
Sign In or Register to comment.