# Sugar dates and NSPredicate

**URL:** https://talk.remobjects.com/t/sugar-dates-and-nspredicate/6093
**Category:** Elements RTL
**Created:** [April 28, 2015, 11:19am UTC](https://talk.remobjects.com/t/sugar-dates-and-nspredicate/6093 "2015-04-28T11:19:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jeremy](https://talk.remobjects.com/user_avatar/talk.remobjects.com/jeremy/32/10_2.png) [@jeremy](https://talk.remobjects.com/u/jeremy)
#### Post date: [April 28, 2015, 11:19am UTC](https://talk.remobjects.com/t/sugar-dates-and-nspredicate/6093/1 "2015-04-28T11:19:04Z")

</div>

I have a problem when using Sugar’s dates when using them with NSPredicate. If I use the following:

```
var startDate,endDate : NSDate;
  endDate:= NSDate.date;
    var components: NSDateComponents := NSCalendar.currentCalendar().components((NSCalendarUnit.CalendarUnitDay or NSCalendarUnit.CalendarUnitMonth) or NSCalendarUnit.CalendarUnitYear) fromDate(endDate);
    var comps: NSDateComponents := new NSDateComponents;
    comps.setDay(1);
    comps.setMonth(components.month);
    comps.setYear(components.year);
    startDate := NSCalendar.currentCalendar().dateFromComponents(comps);
NSLog('start %@, end %@',startDate,endDate);
datePredicate:=NSPredicate.predicateWithFormat('visitDate>=%@ AND visitDate<%@',startDate,endDate);

```

then it works fine, and the start/end dates in NSlog look like this:

```
start 2015-03-31 23:00:00 +0000, end 2015-04-28 11:12:32 +0000

```

If I do this with Sugar:

```
  var startDate,endDate : Sugar.DateTime;
  endDate:= sugar.DateTime.Now;
  startDate:= endDate.AddDays(-endDate.Day+1);
  NSLog('start %@, end %@',startDate,endDate);
  datePredicate:=NSPredicate.predicateWithFormat('visitDate>=%@ AND visitDate<%@',startDate,endDate);

```

then it crashes with

```
-[DateTime timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7fc458e0bb30

```

and the format of the date is different:

```
start 01/04/2015 12:17:54, end 28/04/2015 12:17:54
```
