-1

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

Kamil'
  • 1
  • 1

1 Answers1

0

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.

Ponder Stibbons
  • 14,723
  • 2
  • 21
  • 24
  • Thank you, it was usefull, I think the problem os with missing zeros before hours! – Kamil' Apr 27 '23 at 17:13
  • Yes, missing zeros caused an error. Also please read: [How do I insert datetime value into a SQLite database?](https://stackoverflow.com/questions/1933720/how-do-i-insert-datetime-value-into-a-sqlite-database). – Ponder Stibbons Apr 27 '23 at 20:18