Compare dates - overlooking the hour part
<p>I frequently use the NSDate compare method - but I want to consider two dates similar if they are equal in year, month, day. I have made a procesure called "cleanDate" to remove the hour part before I compare.</p>

<pre><code>-(NSDate*)cleanDate:(NSDate*)date {
    NSCalendarUnit unitflags;
    NSDateComponents *component;  
    NSCalendar *calendar;
    calendar=[[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
    unitflags=NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    component=[calendar components:unitflags fromDate:date];
    return [calendar dateFromComponents:component]; //Dato uten klokke    
}
</code></pre>

<p>But my dates come out as:</p>

<p>2011-10-28 22:00:00
and some dates as:
2011-10-28 23:00:00</p>

<p>I want the hour part to be similar, e.g. 00:00.</p>

<p>Whats wrong? Does it have something to do with daylight saving time? Other? Thanks.</p>
