Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update a firebird timestamp field to remove milliseconds part?

Is there a simple update statement I can execute to update a timestamp field in a firebird database to remove millisecond part.

so current value is: 9-DEC-2013 8:55:57.3560 i want to update it to be: 9-DEC-2013 8:55:57.0000

I need a generic update statement that calculates the new timestamp based upon the old timestamp.

like image 997
srayner Avatar asked Jun 09 '14 10:06

srayner


1 Answers

There is no standard function in Firebird to do this. However with help of the built-in functions EXTRACT and DATEADD you will be able to construct this.

DATEADD(-1 * EXTRACT(MILLISECOND FROM theTimestamp) MILLISECOND TO theTimestamp)

The only problem with this solution is that it doesn't work correctly if your timestamps have a 100 microsecond part, as the documentation of DATEADD states:

<amount> ::= an integer expression (negative to subtract)

And the 100 microsecond part is a decimal fraction of the amount, and can't be changed this way. I have filed ticket CORE-4457 to have this changed, and starting with Firebird 3, DATEADD(... MILLISECOND TO ...) will now accept a fractional value.

However as a lot of client libraries only use or support millisecond precision this probably will not affect you (even the built-in CURRENT_TIME and CURRENT_TIMESTAMP are limited to millisecond precision).

like image 154
Mark Rotteveel Avatar answered Jan 02 '23 13:01

Mark Rotteveel