How to check that certain date in between of date?

前端 未结 2 1742
春和景丽
春和景丽 2020-12-12 06:46

I have a database in that there are two column start and end. start and end are in DD.MM.YYYY format.

I have a date which is also in DD.MM.YYYY format. How

相关标签:
2条回答
  • 2020-12-12 07:16

    Use this below code. It will return number of days between two dates. Date are in format YYYY-MM-DD

    YourDatabse database=new YourDatabse (getApplicationContext(), 1);
     SQLiteDatabase sqlite=database.getReadableDatabase();
                Cursor fetch=sqlite.rawQuery("SELECT julianday('"+date2+"') - julianday('"+date1+"')", null);
                fetch.moveToFirst();
                sqlite.close();
                int noOfDays=fetch.getInt(0);
    
    0 讨论(0)
  • 2020-12-12 07:21

    As Jon Skeet wrote, you should have stored the dates in yyyy-mm-dd format.

    However, it might be possible to convert your date values into proper date values on the fly by reordering the fields (if the fields in the string have a fixed length):

    SELECT *
    FROM MyTable
    WHERE '2013-03-11' BETWEEN substr(StartDate, 7, 4) || '-' ||
                               substr(StartDate, 4, 2) || '-' ||
                               substr(StartDate, 1, 2)
                           AND substr(EndDate, 7, 4) || '-' ||
                               substr(EndDate, 4, 2) || '-' ||
                               substr(EndDate, 1, 2)
    
    0 讨论(0)
提交回复
热议问题