Carl
Carl

Reputation: 861

Sqlite datetime greater than for a particular month

I am trying to select data based on if a month-year is greater than another month-year in SQLITE using the following query:

SELECT id, start_date, end_date FROM recur WHERE strftime('%m%Y', start_date) <= '122012' AND strftime('%m%Y', end_date) >= '122012'

I have a row in the database with:
  start_date = 2012-12-01
  end_date = 2015-05-01

The problem seems to be with the greater than function, and after changing the data around does not seem to be able to carry out the greater than. Can anyone help?

Upvotes: 1

Views: 1006

Answers (1)

CL.
CL.

Reputation: 180210

You must place the year first so that it gets a greater weight in the string comparison:

strftime('%Y%m')

Upvotes: 1

Related Questions