0
votes

I have a question about core data date attributes.

I know that date attributes are stored always as a timestamp representing a time interval since a reference date.

Due to this property, it is very difficult to compare date attribute values without leaving out the time part of them.

In my case I am getting lots of problems sorting objects in a table view.

The question is simple, if I always put a certain time (e.g. 03:00 am) as part of the date attribute, could I be sure that all date attributes for a certain date are equal?

How could I define a date to be stored as core date object attribute with a fixed time (e.g. 2014-01-30 03:00 am).

UPDATED

I am using this code to obtain the today date at 10:00 am:

    NSDate *now = [NSDate date];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
    [components setHour:10];
    NSDate *todayDate = [calendar dateFromComponents:components];

     NSLog(@"TODAY DATE AT 10:00AM %@",todayDate);

But the log shows another time:

TODAY DATE AT 10:00AM 2014-01-30 17:00:00 +0000

1

1 Answers

0
votes

Make the date using only the year, month and day components from the original date. See details in NSDateComponents and NSCalendar dateFromComponents documentation.