0
votes
  • In my sqlite data base I have a field for time.
  • till now i used time with type 'varChar'. it is working perfectly
  • But now i need to change the type in to DateTime.
  • how can i change the followin queries to convert from varchar to date & time type. -in my tabele columns are 'time'(DATETIME), 'Comments'(VARCHAR)

    • in select all method.

    (NSMutableArray *)selectAllFromDB {

    time=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectAllStmt, 0)];

} __

-in insert method

-(BOOL)insertIntoDB:(NSMutableDictionary *)dict
{
        time=[dict objectForKey:@"time"];

        if(sqlite3_bind_text(insertStmt, 1, [time UTF8String], -1, SQLITE_TRANSIENT) != SQLITE_OK) 
        {
            return NO;
        }

}

how to modify these queries for date data type

1

1 Answers

1
votes

Try this:-

-(BOOL)insertIntoDB:(NSMutableDictionary *)dict

{

time=[dict objectForKey:@"time"];

if((sqlite3_bind_double(insert_statement, 1, [time timeIntervalSince1970])) != SQLITE_OK)

    {
        return NO;
    }

}