Anko: How to store dates and booleans?

Created on 31 Mar 2018  路  2Comments  路  Source: Kotlin/anko

Hi there!

I'm new to Anko SQLite and wondering how to save dates and booleans, because I found only the following types:

val NULL: SqlType = SqlTypeImpl("NULL")
val INTEGER: SqlType = SqlTypeImpl("INTEGER")
val REAL: SqlType = SqlTypeImpl("REAL")
val TEXT: SqlType = SqlTypeImpl("TEXT")
val BLOB: SqlType = SqlTypeImpl("BLOB")

Source: https://github.com/Kotlin/anko/blob/master/anko/library/static/sqlite/src/sqlTypes.kt#L39

I could convert both to integers (unix timestamp and 0/1), but is this a good practise?

How do you sort by date?

Thanks in advance!

Most helpful comment

SQlite itself doesn't have dates and booleans, instead sqlite uses integer for both

All 2 comments

SQlite itself doesn't have dates and booleans, instead sqlite uses integer for both

@seaskyways Thank you. I used GreenDAO before and wasn't aware of that.

For others:

SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

  • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
  • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
  • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

Source: https://www.sqlite.org/datatype3.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

red1004g picture red1004g  路  5Comments

Anilugale picture Anilugale  路  4Comments

AndwareSsj picture AndwareSsj  路  4Comments

nkanellopoulos picture nkanellopoulos  路  4Comments

vlonjatg picture vlonjatg  路  3Comments