How to Get Month Without Leading Zeros in SQLite?

Get month without leading zeros from SQLite DATE/DATETIME Column

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 leading zeros 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   |
+-------+

Hope you found this post useful. It was published . Please show your love and support by sharing this post.