Example 1
Read the year from a launch date
The output is the same year number even though the extraction function differs.
Engine-specific syntax
Setup
CREATE TABLE products (launch_date DATE);
INSERT INTO
products (launch_date)
VALUES
('2022-07-15');SQL
SELECT
EXTRACT(
YEAR
FROM
launch_date
) AS launch_year
FROM
products;| launch_year |
|---|
| 2022 |
Engine-specific syntax
Setup
CREATE TABLE products (launch_date DATE);
INSERT INTO
products (launch_date)
VALUES
('2022-07-15');SQL
SELECT
YEAR (launch_date) AS launch_year
FROM
products;| launch_year |
|---|
| 2022 |
Engine-specific syntax
Setup
CREATE TABLE products (launch_date DATE);
INSERT INTO
products (launch_date)
VALUES
('2022-07-15');SQL
SELECT
CAST(strftime ('%Y', launch_date) AS INTEGER) AS launch_year
FROM
products;| launch_year |
|---|
| 2022 |
SQL Server uses `YEAR()` while the others can use `EXTRACT(...)` in this example.