Get month from DATETIME in sqlite

2019-01-12 02:27发布

I am trying to get extract the month from a DATETIME field in SQLite. month(dateField) does not work as well as strftime('%m', dateStart).

Any ideas?

4条回答
地球回转人心会变
2楼-- · 2019-01-12 03:12
SELECT strftime('%m', datefield) FROM table 

If you are searching the month name, text month names does not seems to be supported by the core distribution of SQLite

查看更多
萌系小妹纸
3楼-- · 2019-01-12 03:15

I'm guessing you want to get the month as a string. Not the most friendly looking but you probably see the point. Just replace date('now') with your variable.

select case strftime('%m', date('now')) when '01' then 'January' when '02' then 'Febuary' when '03' then 'March' when '04' then 'April' when '05' then 'May' when '06' then 'June' when '07' then 'July' when '08' then 'August' when '09' then 'September' when '10' then 'October' when '11' then 'November' when '12' then 'December' else '' end
as month 
查看更多
何必那么认真
4楼-- · 2019-01-12 03:22

I don't understand, the response is in your question :

select strftime('%m', dateField) as Month ...
查看更多
狗以群分
5楼-- · 2019-01-12 03:28

Try using the following:

select strftime('%m', datetime(datefield, 'unixepoch')) as month from table
查看更多
登录 后发表回答