I am trying to retrieve the month value of a calculation :
SELECT strftime('%m', 'now') - strftime('%m', e.date) AS something FROM ...
But here are the results I get and what I really want :
NOW - 2012-02-03 = 0 // want 11
NOW - 2012-11-02 = -9 // want 3
NOW - 2012-02-02 = 0 // want 12
NOW - 2012-01-02 = 1 // want 13
As I can see I can almost get the right values by doing sqlResult + 12 (except for first example) but is there a way to achieve this directly in the SQL statement and to get exact values in every case ?
EDIT : Finally here is the solution
SELECT CAST ((julianday('now') - julianday(e.date_retour)) / 30 AS integer) AS something
You are not really looking at difference between two months but, considering their years as well.
So you need to do like this:
SQLite (SQL.js) Demo