Android - SQLite - SELECT BETWEEN Date1 AND Date2

后端 未结 4 1535
暖寄归人
暖寄归人 2020-12-21 06:35

Mac OS-X

Android

Eclipse with ADT

SQLite

I\'m new to creating Android Apps and Ive researched this heavily but I\'m getting nowhere. I need

4条回答
  •  北海茫月
    2020-12-21 07:25

    Not sure where you read that Date / Time should be stored as strings !!! I dis-agree.

    I prefer storing Date / Times as INTEGER values. Read: http://www.sqlite.org/datatype3.html#datetime

    When Inserting data, convert your Date / time as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. For e.g. 1st Jan 2012 00:00:00 GMT is represented as 1356998400000

    The Android Date / Calendar classes have built in functions to convert dates in UNIX Times and vice versa.

    Check : http://developer.android.com/reference/java/util/Date.html#getTime%28%29

    When selecting, you can use your normal select statements like BETWEEN or anything you prefer.

    I have been using this for many years and it works like a charm :D

提交回复
热议问题