Subject Re: [firebird-support] Subtracting minutes from a timestamp
Author Ivan Prenosil
> I'm wanting to select items that have a timestamp value that's a certain
> number of minutes from current_timestamp. E.g., to select items that
> have some_date within the last 10 minutes, I'm trying something like:
>
> select * from foo where some_date - (10.0/(24.0*60.0)) >=
> current_timestamp
>
> This is based on the documentation that says the decimal portion of a
> number is added as minutes to the timestamp value.
>
> Apart from this being a very awkward way to express an interval, there
> are rounding errors -- e.g. the expression of 10 minutes above appears
> to behave more like 9 minutes.

It is even less than 9 minutes. It is because you are using
only three decimal places, which is too few. Better use floating
values/arithmetic, compare:

SELECT CAST('2000-1-1 0:0' AS TIMESTAMP) + 10.0/(24.0*60.0) FROM RDB$DATABASE;
========================
2000-01-01 00:08:38.4000

SELECT CAST('2000-1-1 0:0' AS TIMESTAMP) + 10/1440e0 FROM RDB$DATABASE;
========================
2000-01-01 00:10:00.0000

Ivan
http://www.volny.cz/iprenosil/interbase/