Archive for January, 2009

Extrair parte de um campo Data (Datepart em Firebird)

Select
Extract(Day From current_date)
, Extract(Month From current_date)
, Extract(Year From current_date)
from rdb$database;
CURRENT_DATE    CURRENT_TIMESTAMP
13.01.2009    13.01.2009 19:28
Select
Extract(Day From current_date)
|| ‘-’
|| Extract(Month From current_date)
|| ‘-’
|| Extract(Year From current_date)
from rdb$database;
->  13-1-2009

How to get the Firebird server date and time?

There are two variables available, CURRENT_DATE which returns the current date and CURRENT_TIMESTAMP which returns date and time. You can use those in SQL statements:

insert into t1 values(10, CURRENT_TIMESTAMP);
To query the current time, use this:

Select current_date, current_timestamp
from rdb$database;

You need to select from something and rdb$database is a convenient one-row table that is present in each [...]

How to calculate hours, minutes or seconds between two time values?

If you have time values, just subtract them, and you’ll get the interval length in seconds:
select end_time - start_time
from …
If you want to get minutes, divide the result by 60, and if you want hours by 3600.
If you have timestamps instead of times, the difference is in days, so you if you want [...]