2

A parse object in my database has a date field. I want to use a date that the user selects as the query.

query.whereKey("dateFieldParse", equalTo: janFirst)

I'm not sure how to set up this "janFirst" field. I know it has to be somehow formatted for parse retrieval but what is this format.

I tried setting the components in an NSDate object but it doesn't seem to work.

let userCalendar = NSCalendar.currentCalendar()
let janFirstComponent = NSDateComponents()

janFirstComponent.year = 2014
janFirstComponent.month = 1
janFirstComponent.day = 1
janFirstComponent.hour = 0
janFirstComponent.minute = 0

var janFirst: NSDate = userCalendar.dateFromComponents(janFirstComponent)!

....

query.whereKey("dateFieldParse", equalTo: janFirst)

One more small thing: is the hours and seconds, and even the year, necessary for retrieval? I'm only really using the month and date.

The code for Parse and Swift still seems to be very limited and I can't seem to find anything at all for retrieving dates (+ I'm still very much a iOS/swift noob). Any help, even some general steps as to what to do would be greatly appreciated.

Thanks in advance. :)

2 Answers 2

3

I actually had it right, I just didn't realize timezones were an issue with Parse. It seems the timezone had to be set to "GMT" (Parse's timezone). For anyone that might face a similar issue, the wee bit of code is below.

let userCalendar = NSCalendar.currentCalendar()        
let timeZone = NSTimeZone(abbreviation: "GMT")
userCalendar.timeZone = timeZone!
Sign up to request clarification or add additional context in comments.

Comments

0

In your Parse data browser, make sure your parse object is set to Date and you variable is set to NSDate

1 Comment

Thanks man, I actually had it right. I realized it had to do with the timezone. My "janFirstComponent.hour = 0" had to be set to -5 or I had to set the timezone to "GMT" to match Parse's timezone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.