Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let datePredicate = NSPredicate(format: "date == Date()")
- // Get the current calendar with local time zone
- var calendar = Calendar.current
- calendar.timeZone = NSTimeZone.local
- // Get today's beginning & end
- let dateFrom = calendar.startOfDay(for: Date()) // eg. 2016-10-10 00:00:00
- let dateTo = calendar.startOfDay(for: Date(timeIntervalSinceNow: 60*60*24)) // eg. 2016-10-11 00:00:00
- // Note: Times are printed in UTC. Depending on where you live it won't print 00:00:00 but it will work with UTC times which can be converted to local time
- // Set predicate as date being today's date
- let datePredicate = NSPredicate(format: "%@ <= date && date < %@", [dateFrom, dateTo])
- fetchRequest.predicate = datePredicate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement