12.14'NOW'

Current date and/or time in cast context

TypeCHAR(3), or depends on explicit CAST

'NOW' is not a variable, but a string literal or datetime mnemonic. It is, however, special in the sense that when you CAST() it to a datetime type, you will get the current date and/or time. If the datetime type has a time component, the precision is 3 decimals, i.e. milliseconds. 'NOW' is case-insensitive, and the engine ignores leading or trailing spaces when casting.

'NOW' always returns the actual date/time, even in PSQL modules, where Section 12.2, “CURRENT_DATE, Section 12.4, “CURRENT_TIME and Section 12.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 12.2, “CURRENT_DATE, Section 12.4, “CURRENT_TIME and Section 12.5, “CURRENT_TIMESTAMP is generally preferable to casting 'NOW'. Be aware though that CURRENT_TIME defaults to seconds precision; to get milliseconds precision, use CURRENT_TIME(3).

Note

Firebird 3.0 and earlier allowed the use of 'NOW' in datetime literals (a.k.a. "`shorthand casts"`), this is no longer allowed since Firebird 4.0.

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