samedi 4 juillet 2015

Storing and Retrieving Dates in SQLite FMDB with Swift

I want to store and retrieve dates into an SQLite DB using FMDB using Swift. Sounds simple enough...

The field is created with

TIMESTAMP DATETIME

I am trying to save to it with (overly elaborate code to prove I have a valid date before I reverting it back for saving purposes)

let date = NSDate()
var formatter = NSDateFormatter();
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ";
let defaultTimeZoneStr = formatter.stringFromDate(date);
NSLog("DATE = %@", defaultTimeZoneStr)                
locationRecord.locationCreatedDatestamp = formatter.dateFromString(defaultTimeZoneStr)!

The NSLog writes a legitimate date. locationRecord.locationCreatedDatestamp is an NSDate().

And then saving it with the old faithful

INSERT INTO

When I try and retrieve it the errors imply the field is nil so suspect I'm not saving it correctly in the first place.

What (several) am I doing wrong....?

Aucun commentaire:

Enregistrer un commentaire