0

I have a Date column in my Sqlite database. When I put some NSDate value in it, and open the Sqlite file through graphical tools. I get some value like 530963469.705571. The corresponding date is around today or yesterday.

It's clearly not Unix epoch datestamp value. What exactly does this value mean?

I need to change this value in order to debug my app.

steveluoxin
  • 419
  • 4
  • 14
  • Possible duplicate of [Saving Date to SQLite](https://stackoverflow.com/questions/8165033/saving-date-to-sqlite) – Imad Ali Oct 30 '17 at 05:36
  • @ImadAli Not the same question. My codes work fine. I just need to know what is this value so I can change it. – steveluoxin Oct 30 '17 at 05:38
  • There is no date type in SQLite, so what is the type of your `Date` column? Also, it would obviously help if you show us the code you have for writing to this column. As of now, I suspect this is more of an iOS question than a SQLite one. – Tim Biegeleisen Oct 30 '17 at 05:46

1 Answers1

2

From the documentation

NSDate objects encapsulate a single point in time, independent of any particular calendrical system or time zone. Date objects are immutable, representing an invariant time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001).

Since sqlite does not support NSDate directly, the date is persisted as the underlying value. 530963469.705571 represents the number of seconds between 00:00:00 UTC on 1 January 2001 and the time when you created the NSDate

You can use the NSDate initialiser init(timeIntervalSinceReferenceDate:) to create an NSDate from the time interval value.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Now I figured it out. It's **Seconds Since 0001-01-01 AD**. By the way, I created `Data Model` file, and created an `entity`, and created a `attribute` which I can select a `Date` type. Thanks! – steveluoxin Oct 30 '17 at 06:08
  • You generally would use `timeIntervalSince1970` instead of `timeIntervalSinceReferenceDate:`, as you can then use the `unixepoch` option in the SQLite date functions/tools to display the date in a user-friendly format. – Rob Jan 23 '18 at 18:34