Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newdev

macrumors newbie
Original poster
Aug 5, 2008
4
0
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?
 
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.
 
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 :)
 
what if

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
 
index 1

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.