DotNetFirebird.org DotNetFirebird
Using Firebird SQL in .NET.
Sunday, January 09, 2005

Date and Time Calculations

When doing arithmetic operations with TIMESTAMP values, Firebird works with them as decimal number, where
  • the integral fraction is the number of days
  • the decimal fraction is the part of a day
For example:
  • Two days: 2.0
  • One hour: 1.0/24.0
  • One minute: 1.0/1440.0
  • One second: 1.0/86400.0
Extracting the smaller units from a TIMESTAMP value:
  • Number of seconds: VALUE*86400.0
  • Number of minutes: VALUE*1440.0
  • Number of hours: VALUE*24.0
Don't forget the decimal point in the numbers (e.g. 1.0), otherwise the result will be integer. I spent a lot time debugging a calculation that didn't work because I was dividing by an integer. Since that time, I remember.

Comments:

Blog comments are closed.



Previous

Archives