9.12. 'NOW'
Available inDSQL, PSQL, ESQL
Changed in2.0
TypeCHAR(3)
Description'NOW'
is not a variable but a string literal.
It is, however, special in the sense that when you CAST()
it to a date/time type, you will get the current date and/or time.
The fractional part of the time used to be always
, giving an effective seconds precision.
Since Firebird 2.0 the precision is 3 decimals, i.e. milliseconds. .0000
'NOW'
is case-insensitive, and the engine ignores leading or trailing spaces when casting.
Please be advised that the shorthand expressions are evaluated immediately at parse time and stay the same as long as the statement remains prepared.
Thus, even if a query is executed multiple times, the value for e.g.
won’t change, no matter how much time passes.
If you need the value to progress (i.e. be evaluated upon every call), use a full cast.timestamp 'now'
Examples
|
select 'Now' from rdb$database
|-- returns 'Now'
|
|select cast('Now' as date) from rdb$database
|-- returns e.g. 2008-08-13
|
|select cast('now' as time) from rdb$database
|-- returns e.g. 14:20:19.6170
|
|select cast('NOW' as timestamp) from rdb$database
|-- returns e.g. 2008-08-13 14:20:19.6170
Shorthand syntax for the last three statements:
|select date 'Now' from rdb$database
|select time 'now' from rdb$database
|select timestamp 'NOW' from rdb$database
'NOW'
always returns the actual date/time, even in PSQL modules, where Section 9.2, “CURRENT_DATE
”, Section 9.4, “CURRENT_TIME
” and Section 9.5, “CURRENT_TIMESTAMP
” return the same value throughout the duration of the outermost routine. This makes'NOW'
useful for measuring time intervals in triggers, procedures and executable blocks.Except in the situation mentioned above, reading Section 9.2, “
CURRENT_DATE
”, Section 9.4, “CURRENT_TIME
” and Section 9.5, “CURRENT_TIMESTAMP
” is generally preferable to casting'NOW'
. Be aware though thatCURRENT_TIME
defaults to seconds precision; to get milliseconds precision, useCURRENT_TIME(3)
.