Sqlite calculates the difference in days between the date formats of YYYYMMDD in Query

I recorded the treatment date (date) and date (date) date in the YYYYMMDD format for some patient records. I want to request records that rdate-tdate result is less than 30.

My attempt was

SELECT * FROM table WHERE (rdate - tdate) <= 30;

Somehow this is the right query, but the results are something else. Let me know if you have a solution.

+4
source share
2 answers

I was able to work this way with @cms answer, and this is what worked for me.

SELECT *,(julianday(substr(rdate`,1`,4)||"-"||substr(rdate`,5`,2)||"-"||substr(rdate`,7`,2))-julianday(substr(tdate`,1`,4)||"-"||substr(tdate`,5`,2)||"-"||substr(tdate`,7`,2)))'difference' FROM table WHERE difference <= 30.0

He worked like a charm

+2
source

SQLite /. NUMERIC TEXT . /, .

, , julianday , , , .

SELECT * FROM table WHERE (julianday(rdate)-julianday(tdate)) <= 30  ;

SQLite

, NUMERIC. , , , . , , .

SELECT rdate,tdate,
       cast(rdate AS NUMERIC), cast(tdate AS NUMERIC),
       rdate - tdate 
FROM table ;

, .

+7

All Articles