I want to make a database that will hold a date in it(SQLite). Now first to ask is what is the right syntax to declare a date column. The second i want to know is how to insert date in it after that. And the third thing i want to know is how to select dates between, for example to select all rows which contain date between 01/05/2010 and 05/06/2010.
Thank you
From the SQLite Data Types documentation:
Take your pick. I'd go for TEXT or INTEGER. The INTEGER will be faster. If you need to store dates past 1970 (e.g. birthdates, etc), then I'd go for TEXT. If you just need to store creationtime/modificationtime, etc for now and the future, then go for INTEGER.
Use
PreparedStatement#setString()
or#setLong()
respectively.Use the standard SQL
BETWEEN
clause for this. You first need to convert the date accordingly using the built-in date and time functions.A convenient syntax for declaring a date column is like this:
This will default inserted values to the current datetime. Or you can use CURRENT_DATE, or CURRENT_TIME values. You won't have to insert a timestamp manually each time you create a row.
You can read about this approach here: Android insert datetime value in SQLite database