Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create a timestamp field in sqlite so a Core Data object with a NSDate field is initialized correctly?
    text
    copied!<p>After reading <a href="http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data" rel="nofollow">this great tutorial</a> on pre-building a sqlite database to be used by Core Data, I'm still stuck on datetime columns. I've cross-posted my question to try and get some help because I'm stuck on this. </p> <p>My application uses a pre-built database in a read-only fashion, it is a transit application and the data source is schedule data. Dates are in the following format (from the data provider): "20110223" (which would be written "Februrary 23, 2011"). I have been reviewing the post and comments talking about the iPhone reference date of 2001, and adjusting date/time values based on a delta of seconds since that time prior to inserting into sqlite. My importer script defines a TIMESTAMP column to store this delta of seconds. An example of the column after being stored would be "319766400".</p> <p>Here is a snippet of Ruby as an example of what my script does:</p> <pre><code>&gt;&gt; delta_seconds = Time.parse("20110223") - Time.local(2001, 1, 1, 0, 0, 0) =&gt; 320112000.0 &gt;&gt; Time.at(delta_seconds) =&gt; Fri Feb 22 19:00:00 -0500 1980 </code></pre> <p>Note that asking for a time from the delta_seconds (Time.at(delta_seconds)) shows the right day of the year (Feb 22) but in the year 1980, which is 10 years after EPOCH---which seems right. In Core Data I've defined my model attribute that maps to this DB field as "NSDate". However, when I fire up the simulator and check the debugger, for each object I ask for the the NSDate field (start_date) as follows: [object valueForKey:@"start_date"] which gives me "2001-08-21 18:10:19 GMT". In other words, it doesn't seem to be reading the delta seconds value. If it did, I'd expect it to apply "10 years worth of seconds" in this case and come up with a "2011" year date.</p> <p>Can you spot something I'm doing wrong? Any suggestions on potential fixes? Thanks! (iOS 4.1 Core Data)</p> <p><strong>Or</strong>: can someone post a value from their sqlite database that Core Data reads, from a column that is intended to be the source of a NSDate field? An example value from my database is <code>320371200</code> which appears to not work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload