Issue with NULL values in date column using strftime function in SQLite

113 Views Asked by At

I am working with a SQLite database that includes a column with dates in the format "YYYY-MM-DD". I am trying to extract the year and month from each date using the strftime function, but for these rows "2021-02-14 6:37:00", "2021-02-19 3:35:00" the function returns NULL.

I tried to check if SELECT from this column shows all rows. And it shows all dates correctly. I would like to know why NULL appears

1

There are 1 best solutions below

2
Ponder Stibbons On

SQLite documentation:

Date and time values can be stored as text in a subset of the ISO-8601 format, numbers representing the Julian day, or numbers representing the number of seconds since (or before) 1970-01-01 00:00:00 UTC (the unix timestamp).

ISO 8601 format - wiki:

Each date and time value has a fixed number of digits that must be padded with leading zeros.

dbfiddle demo for values with and without leading zeros.