Extracting Date and Time Information (Embedded SQL Guide)
Go Up to Querying the Database for Current Date and Time Information
The EXTRACT
() function extracts date and time information from databases. EXTRACT
() has the following syntax:
EXTRACT (part FROM value)
The value passed to the EXTRACT
() expression must be DATE
, TIME
, or TIMESTAMP
. Extracting a part that doesn’t exist in a data type results in an error. For example:
EXTRACT (TIME FROM aTime)
would be successful, while a statement such as:
EXTRACT (YEAR from aTIME)
would fail.
The data type of EXTRACT
() expressions depends on the specific part being extracted:
Extract Part | Resulting data type | Representing |
---|---|---|
|
|
Year, range 0-5400 |
|
|
Month, range 1-12 |
|
|
Day, range 1-31 |
|
|
Hour, range 1-23 |
|
|
Minute, range 1-59 |
|
|
Second, range 0-59.9999 |
|
|
Day of the week, range 0-6 |
|
|
Day of the year, range 1-366 |