Search code examples
iosswiftckquery

Swift 3 How to create Date for a specific date


In swift 2.3, I wrote a function that takes the date 6-01-16, converts it to NSDate, then utilizes that in a CKQuery. I'm not sure how to update this for Swift 3.

Here's my current code:

let formatter = DateFormatter()
    formatter.dateFormat = "yyyymmdd"
    let olddate = formatter.date(from: "20160601")
    print(olddate)

This isn't working, how should I change my syntax?


Solution

  • mm is the format for minutes; you mean MM for months. Your dateFormat should be:

    "yyyyMMdd"