Current date in cast context
Type
CHAR(5)
, or depends on explicit CAST
'TODAY'
is not a variable, but a string literal or date mnemonic.It is, however, special in the sense that when you CAST()
it to a date/time type, you will get the current date.If the target datetime type has a time component, it will be set to zero.'TODAY'
is case-insensitive, and the engine ignores leading or trailing spaces when casting.
Note
|
-
'TODAY' always returns the actual date, even in PSQL modules, where [fblangref50-contextvars-current-date], [fblangref50-contextvars-current-time] and [fblangref50-contextvars-current-timestamp] return the same value throughout the duration of the outermost routine.This makes 'TODAY' useful for measuring time intervals in triggers, procedures and executable blocks (at least if your procedures are running for days).
-
Except in the situation mentioned above, reading CURRENT_DATE , is generally preferable to casting 'TODAY' .
-
Firebird 3.0 and earlier allowed the use of 'TODAY' in datetime literals (a.k.a. "`shorthand casts"`), this is no longer allowed since Firebird 4.0.
-
When cast to a TIMESTAMP WITH TIME ZONE , the time reflected will be 00:00:00 in UTC rebased to the session time zone.
|
Examples
select 'Today' from rdb$database
-- returns 'Today'
select cast('Today' as date) from rdb$database
-- returns e.g. 2011-10-03
select cast('TODAY' as timestamp) from rdb$database
-- returns e.g. 2011-10-03 00:00:00.0000