You can get month from a SQLite DATE
/DATETIME
column, for example, by using strftime()
function with the %m
modifier, like so:
SELECT strftime("%m", "2021-09-12 00:00:00") as month
This would result in:
+-------+ | month | +-------+ | 09 | +-------+
However, this would give you the current month with leading zero (for months below 10
). To remove the leading zero from the result, you can simply use ltrim()
, for example, like so:
SELECT ltrim(strftime("%m", "2021-09-12 00:00:00"), "0") as month
This would result in:
+-------+ | month | +-------+ | 9 | +-------+
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.