Subject Re: Iterating through the first day of a month between two dates
Author Adam
--- In firebird-support@yahoogroups.com, "eddressel" <eddressel@...>
wrote:
>
> FB 1.5
>
> I am writing a stored proc where it is passed two dates, StartDate and
> EndDate, and I need to iterate through each first day of the month
> between the two dates:
>
> CheckDate := StartDate;
> while CheckDate < EndDate do
> begin
> ...other SQL coding using CheckDate
> CheckDate = get the next month, first day for CheckDate);
> end;
>
> Is there an easy way to do the CheckDate ?

The easiest (though not most efficient) way is to just add 1 day until
the month changes. Unless you are doing this tens of thousands of
times, the performance hit would be negligible.

--
CurrentMonth = EXTRACT(month FROM CheckDate);
while (CurrentMonth = EXTRACT(month FROM CheckDate)) do
begin
CheckDate = CheckDate + 1;
end
--

You may want to start at StartDate-1 though just in case they pass in
the first of a given month.

Adam