Get year from a correct formatted field

Get year from a correct formatted field

I'm using a SQLite DB, and I'm trying to get the year part in a date field (in SQLite there is not an data type for date/time but the field has to be TEXT type and formatted in a proper way).

As it doesn't work I moved in simplified way. This sqlite> SELECT STRFTIME('%Y', '2023') ; yields NULL; and with the full date sqlite> SELECT STRFTIME('%Y', '2023-1-1') ; it returns -4707.

Answer

The right timeformat was sqlite> SELECT STRFTIME('%Y', '2023-01-01');

Which return a correct 2023

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles