• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do I compare two NSDates using NSPredicate & Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I compare two NSDates using NSPredicate & Core Data


  • Subject: Re: How do I compare two NSDates using NSPredicate & Core Data
  • From: "Sean McBride" <email@hidden>
  • Date: Fri, 9 Apr 2010 14:04:31 -0400
  • Organization: Rogue Research Inc.

On Fri, 9 Apr 2010 12:52:21 -0500, Ashley Clark said:

>>> Thus far I've gotten away with using -predicateWithFormat and scalar
>>> values.  I now need to compare a couple of NSDate instances but am not
>>> sure how to code it up with NSPredicate.  Consider me a 'visual' learner.
>>
>> I'm pretty sure you can use just <, >, ==, etc. with NSDates in
>NSPredicates.
>
>One thing that many people overlook is that NSDates *always* include a
>time component. And if that time wasn't specified explicitly it
>typically defaults to a preset value set in the editing control (if one
>was used) or the current time at the time the date string was parsed.
>
>So, if you were expecting to compare a set of NSDate objects to be on a
>particular date irrespective of their time value... you have a bit of
>work to do. A simple way to approximate the test is to look at a time
>range from midnight to midnight-1 second of the following day.
>
>That of course leaves another issue aside though, that of differing
>timezones. All NSDate objects are converted to the local timezone by
>default and the original timezone information is not stored in the
>object, so an NSDate created as {2010/01/01 23:59 EDT} when read back at
>some later point when the computer is now on the west coast (PDT) would
>show as {2009/12/31 20:59 PDT}.
>
>All of that to say, comparing dates with predicates (or at all) is hard.

I get what you're saying, but a date represents an exact moment in time,
irrespective of location or time zone or any of that.  Sometimes people
may use an NSDate when they probably should be using NSDateComponents,
which you can easily do in a Core Data context using a 'transformable'
attribute.  Comparing NSDateComponents is harder because you also need a
calendar, etc.

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How do I compare two NSDates using NSPredicate & Core Data (From: "Michael A. Crawford" <email@hidden>)
 >Re: How do I compare two NSDates using NSPredicate & Core Data (From: "Sean McBride" <email@hidden>)
 >Re: How do I compare two NSDates using NSPredicate & Core Data (From: Ashley Clark <email@hidden>)

  • Prev by Date: (no subject)
  • Next by Date: Re: NSPipe (NSFileHandle) writedata limit?
  • Previous by thread: Re: How do I compare two NSDates using NSPredicate & Core Data
  • Next by thread: Re: How do I compare two NSDates using NSPredicate & Core Data
  • Index(es):
    • Date
    • Thread