Home > DeveloperSection > Forums > DATETIME type of SQLite & ObjectiveC
Eric Martell
Eric Martell

Total Post:9

Posted on    November-09-2015 3:16 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 599  View(s)
Rate this:

I have created a SQLite table in my app, and I tried to map an object using Objective-C programming.
First attribute of table 'Save_time' of type DATETIME.

Now, I want to create a property on my Obj-C class that will map to the 'save_time' attribute.
I read that Objective C has a class name NSDate, but I am not sure that will map it directly or not?

Tarun Kumar

Total Post:214

Posted on    November-15-2015 10:50 PM

The formatter is important if you are trying to effect the presentation but if you use if for internal storage, you are defining a string which can defeat the DB-engine's ability to use the value for computation, comparison, sorting, etc. Also, if you are going to have different clients inserting the date value into the DB you would have to write conversion functions everywhere.

Use this code and it worked as expected (schema's column defined as DATETIME):

dateExpires = [NSDate dateWithTimeIntervalSinceNow: sqlite3_column_double(queryStmt, 5)];

I inserted into the SQLITE3 db with the Firefox add-on as "4/12/2010" here in Central time zone. Viewing the value of 'dateExpires' in XCode-debugger displayed as:
2015-11-11 13:19:48 -0500
Sure enough, that is the correct time.
Also, to insert into the SQLITE DB you will put the value [NSDate date]

Don't want to miss updates? Please click the below button!

Follow MindStick