Link to home
Start Free TrialLog in
Avatar of firekiller15
firekiller15

asked on

can return only specify date

Delphi
given
Table A

Date A(holidayDate)
--------
3/8/2008
3/22/2008
 
Table B
DateB                             result Date I need to meet my gf
------
from 3/1/2008 to 3/31/2008



below is my code

      while( not vA.EOF) do
      begin
        vB.First;
          while (not vB.Eof) do
          begin
           vWeekday := vB.FieldByName('DateB').AsDateTime;
           vWeekday1 := vB.FieldByName('DateB').AsDateTime - 1;
         
          if (dateof(vWeekday1) =  dateof(vA.FieldByName('DateA ').AsDateTime)) and
          if (DayofWeek(vWeekday) = 1)  then  //here weekday is sunday
          begin
            if (DayofWeek(DateA) > DayofWeek(vweekday-3)) and
            (DayofWeek(DateA) > DayofWeek(vWeekday)) then
            result := vWeekday - 4
            else
            result := vWeekday - 3;
            vB.edit;
            vB.FieldByName('result').value:= result;
            vB.Post;
           end  ;
           vB.next;
         end;
         vA.Next;
        end;


problem above is that it only return the date that has holiday date
example
sunday - 3/9/2008
sunday - 3/23/2008

other sunday like
sunday - 3/16/2008
sunday - 3/30/2008
are not shown
how to make it return other sunday date as well










while( not vA.EOF) do
      begin
        vB.First;
          while (not vB.Eof) do
          begin
           vWeekday := vB.FieldByName('DateB').AsDateTime;
           vWeekday1 := vB.FieldByName('DateB').AsDateTime - 1;
         
          if (dateof(vWeekday1) =  dateof(vA.FieldByName('DateA ').AsDateTime)) and
          if (DayofWeek(vWeekday) = 1)  then  //here weekday is sunday
          begin
            if (DayofWeek(DateA) > DayofWeek(vweekday-3)) and
            (DayofWeek(DateA) > DayofWeek(vWeekday)) then
            result := vWeekday - 4
            else
            result := vWeekday - 3;
            vB.edit;
            vB.FieldByName('result').value:= result;
            vB.Post;
           end  ;
           vB.next;
         end;
         vA.Next;
        end;

Open in new window

Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Please explain what you are trying to achieve? Your coding logic is not making sense to me at the moment...
My suggestion is, to first get the maximum and minimum dates that you have, ie 3/1 and 3/31, and and then subtract them to find out the days between. Then div by 7, and what you find use in a For Loop, and from the First Sunday that you will find go to the next by adding 7 to the datetime value, and exit the loop when the value that you have is > more than your Max Date.

With the for Loop you will return all the Sundays bettween....
* if you have more holidays than just the Sundays, then retrieve the holidays in an array and do a an internal loop trying to match all days between Min and Max with the values in the array.

Hope it helps
ASKER CERTIFIED SOLUTION
Avatar of Y SD
Y SD
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial