Get month from DATETIME in sqlite

前端 未结 7 1345
温柔的废话
温柔的废话 2020-12-01 16:28

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)

7条回答
  •  春和景丽
    2020-12-01 16:51

    Here is my solution that worked for me

    MONTH_DICT={ "Jan" : '01', "Feb" : '02', "Mar" : '03', "Apr" : '04', "May" : '05', "Jun" : '06', "Jul" : '07', "Aug" : '08', "Sep" : '09', "Oct" : 10, "Nov" : 11, "Dec" : 12 }
    
    self.cursor.execute("SELECT * FROM error_log WHERE strftime('%m',Date_column)=?",(MONTH_DICT[query_month],)) 
    
    print('output:', self.cursor.fetchall())
    

提交回复
热议问题