How to store and get datetime value in SQLite

前端 未结 3 1546
感情败类
感情败类 2020-12-28 21:27

My table contains Birthdate field which has datatype as datetime. I want to get all records having birthday today. How can I get it?

3条回答
  •  难免孤独
    2020-12-28 21:48

    SQLite has very poor support for storing dates. You can use the method suggested by Nick D above but bear in mind that this query will result in full table scan since dates are not indexed correctly in SQLite (actually SQLite does not support dates as a built-in type at all).

    If you really want to do a fast query then you'll have to add a separate (integral) column for storing the birth day (1-31) and attach an index for it in the database.

    If you only want to compare dates then you can add a single (INTEGER) column that will store the date UTC value (but this trick won't allow you to search for individual date components easily).

    Good Luck

提交回复
热议问题