sqlite3 and datetime

Discussion in 'iOS Programming' started by newdev, Aug 8, 2008.

  1. newdev macrumors newbie

    Joined:
    Aug 5, 2008
    #1
    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?
     
  2. ayasin macrumors 6502

    Joined:
    Jun 26, 2008
    #2
    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.
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    I agree, and NSDate's dateWithTimeIntervalSince1970: and timeIntervalSince1970 methods are your friends :)
     
  4. jagatnibas macrumors regular

    Joined:
    Jul 28, 2008
    #4
    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
     
  5. jagatnibas macrumors regular

    Joined:
    Jul 28, 2008
    #5
    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
     

Share This Page