vendredi 18 décembre 2015

android sqlite take data between dates

I have 7 columns. BUt problem is in 2 columns, start and end time. They are string.

For example this is an output of a two columns i wanted.

sDate: 2015-12-18 11:11 edate: 2015-12-23 22:11

Now time is 2015-12-18 20:11

so this event is still active because it is ending today in 22:11. Then tomorrow starts again in 11:11

I try to do this:

formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm");//for sqlite
    String selectQuery = "SELECT  * FROM " + TABLE_EVENTS+" WHERE "+KEY_END_TIME+
                " BETWEEN ('"+formatter.format(currentDate.getTime())+"') " +
                "AND ('"+formatter.format(currentDate.getTime()).substring(0,10)+ " 23:59') " +
                "OR WHERE "+KEY_START_TIME+
                " BETWEEN ('"+formatter.format(currentDate.getTime())+"') " +
                "AND ('"+formatter.format(currentDate.getTime()).substring(0,10)+ " 23:59') " +

                " AND "+KEY_TYPE+" = \""+type_+"\""
                +" ORDER BY "+ KEY_START_TIME +" ASC";

This query can not return the date i posted before.

I need substring of the date in that column. Is it possible? I will take only hour of enddate and compare to it.

I dont want to separate date columns to date and hour columns.

Aucun commentaire:

Enregistrer un commentaire