PDA

View Full Version : sqlite3 and datetime




newdev
Aug 8, 2008, 11:04 PM
How do I read a datetime field back from the database?

Also, I have a database table where I insert a row with a datatime column .. now i want to read this back.. how can i do that? any idea?



ayasin
Aug 9, 2008, 12:08 AM
You have to parse it yourself. One weakness of sqlite3 is that it doesn't have a native understanding of datetime even though it provides the column type. The best way to handle this situation is to store an int representing the date and manipulate it yourself.

kainjow
Aug 9, 2008, 12:23 AM
The best way to handle this situation is to store an int representing the date and manipulate it yourself.

I agree, and NSDate's dateWithTimeIntervalSince1970: and timeIntervalSince1970 methods are your friends :)

jagatnibas
Nov 2, 2009, 05:52 AM
but what if I am dealing with dates prior to 1970 ?

if i am aksed to insert a data in precreated table whose schema i am not allowed to change, what would be my approach ? i tried sqlite3_bind_text(addstmt, 1, "28-DEC-1947", -1, SQLITE_TRANSIENT)

I get error "SQL logic error or missing database"

thanks and regards

jagatnibas
Nov 2, 2009, 06:33 AM
i figured out, this statement is not a problem, this returns SQLITE_OK

in fact in sqlite3 field indexes start from 1 not zero :)

regards
Jagat