Subject Re: How do I subtract an integer form a date inside of a stored procedure
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, "M Tuttle \(KS\)"
<miket@s...> wrote:
> Greetings,
>
> I am trying to subtract today's date (dCurrentDate) from the next
payment
> date (NextPmtDueDate) less so many grace days (iAutoDefaultDays)
>
> Here is a portion of my stored procedure:
>
> DECLARE VARIABLE iNumOfDays SMALLINT;
> DECLARE VARIABLE dCurrentDate DATE;
> DECLARE VARIABLE iAutoDefaultDays SMALLINT;
> DECLARE VARIABLE NextPmtDueDate DATE;
> ...
> CurrentDate = CURRENT_DATE;
> iNumOfDays = ((NextPmtDueDate + iAutoDefaultDays) - dCurrentDate);
> ...
>
> In the stored procedure debugger (Database Workbench) I see the
following
> values
> NextPmtDueDate = 38092 "Does not look like dCurrentDate below"
> iAutoDefaultDays = 3
> dCurrentDate = 4/30/2004
> iNumOfDays = 38092
>
> It look like the NextPmtDueDate is shown as an integer value, so I
can add
> iAutoDefaultDays to it. But it look like dCurrentDate is NOT an integer
> value and therefore it does not get subtracted from (NextPmtDueDate +
> iAutoDefaultDays)
>
> In other words (38092 + 3) = 38095 but I cannot subtract today's date
> (4/30/2004) from it.
>
> I simply need to add 3 days to the next payment date and subtract
today's
> date form it.
>
> When I run this through the debugger the procedure will finish and
return
> "Payment 38095 Days Late"
>
> However when I run it from my app I get a "Conversion Error From
String..."
>
> What am I doing wrong?

Michael, dialect 3 is not very familiar to me, so I, out of
curiosity, made test database and:

Create procedure Datearithm
Returns (iNumOfDays SMALLINT, dCurrentDate DATE,
iAutoDefaultDays SMALLINT, NextPmtDueDate DATE)
as
begin
dCurrentDate = CURRENT_DATE;
NextPmtDueDate='5/30/2004';
iNumOfDays = ((NextPmtDueDate + iAutoDefaultDays) - dCurrentDate);
Suspend;
end

and

Select * From Datearithm

all worked exactly as in my beloved dialect 1:

INUMOFDAYS DCURRENTDATE IAUTODEFAULTDAYS NEXTPMTDUEDATE
33 30.04.2004 3 30.05.2004

looks like you declared wrong type for one of variables/parameters in
your procedure or on client side, char instead date for example or try
to return time interval into Date. Perhaps smallint is too small to
store iNumOfDays for some NextPmtDueDate. General recommendation -
don't save money buying matches, short types as smallint, float etc
are tribute for times when computer occupied square of swimming-pool
and amount of RAM and disk space was measured in KBytes.

Best regards,
Alexander.