Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persisting Dates to SQLite3 in an iPhone Application

I am developing an iPhone application that persists data to a SQLite3 database.

For each row I persist I wish to include a 'created date' and a 'last modified date'

My question is what is the recommend approach for storing this information in a table?

The properties are represented as NSDate in my application but I am unsure how to represent this information in my table.

It appears that SQLite3 provides a DATETIME type but does not have a native understanding of how to parse this information.

Any help would be much appreciated.

Thanks in advance.

like image 635
lucasweb Avatar asked Oct 30 '08 18:10

lucasweb


1 Answers

I typically use a double, something like:

sqlite3_bind_double(statement, index, [dateObject timeIntervalSince1970]);

where dateObject is an NSDate*. Then, when getting the data out of the DB, use

[NSDate dateWithTimeIntervalSince1970:doubleValueFromDatabase];
like image 105
drewh Avatar answered Oct 08 '22 05:10

drewh