Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. let datePredicate = NSPredicate(format: "date == Date()")
  2.  
  3. // Get the current calendar with local time zone
  4. var calendar = Calendar.current
  5. calendar.timeZone = NSTimeZone.local
  6.  
  7. // Get today's beginning & end
  8. let dateFrom = calendar.startOfDay(for: Date()) // eg. 2016-10-10 00:00:00
  9. let dateTo = calendar.startOfDay(for: Date(timeIntervalSinceNow: 60*60*24)) // eg. 2016-10-11 00:00:00
  10. // 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
  11.  
  12. // Set predicate as date being today's date
  13. let datePredicate = NSPredicate(format: "%@ <= date && date < %@", [dateFrom, dateTo])
  14. fetchRequest.predicate = datePredicate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement