Date range predicate

Posts   
 
    
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 04-Sep-2007 15:40:03   

I'm on version 2.0.0.0, SelfService, VS 2005 VB.Net

I want to select items where the date range includes a specific date fully or partially. This doesn't work:

Dim myPred As IPredicateExpression = New PredicateExpression()
        myPred.Add(Not (DemSupFields.EndTime < jtlSched.DropDownCalendar.CurrentDate))
        myPred.AddWithAnd(Not (DemSupFields.StartTime > jtlSched.DropDownCalendar.CurrentDate))
DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 04-Sep-2007 15:57:17   
dim filter As New PredicateExpression
filter.Add(PredicateFactory.Between(TransactionDetailFieldIndex.DateTransaction, dateFrom, dateTo))
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 04-Sep-2007 16:08:13   

Thanks, but will that work? Say current date is 25/12/2007. I want to include these:

From 1/11/2007 to 1/3/2008 From 1/11/2007 to 25/12/2007 03:30am From 25/12/2007 03:30am to 4/4/2008

In any case I thought the PredicateFactory is only included for backward compatibility, so I don't generate it.

What I want to replicate is this SQL:

WHERE StartDate not > 25/12/2007 and EndDate not < 25/12/2007

DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 04-Sep-2007 16:30:55   

You're right, FieldBetweenPredicate is better. Shouldn't this work ?

filter.Add(TransactionFields.StartDate < #25/12/2007# And TransactionFields.EndDate > #25/12/2007#) 
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 04-Sep-2007 16:46:31   

Apologies. I also want:

From 25/12/2007 06:15 to 25/12/2007 06:19

This appears to work and I can cope with a workaround:

Dim myPred As IPredicateExpression = New PredicateExpression()
        ' This is long-winded but the NOT operator doesn't seem to work.
        ' Note jtlSched.DropDownCalendar.CurrentDate is date-only, and
        ' the StartTime and EndTime are datetime.

        ' The item starts on this day...
        myPred.Add(DemSupFields.StartTime >= jtlSched.DropDownCalendar.CurrentDate And DemSupFields.StartTime <= DateAdd(DateInterval.Day, 1, jtlSched.DropDownCalendar.CurrentDate))
        ' ...or spans the start of this day
        myPred.AddWithOr(DemSupFields.StartTime < jtlSched.DropDownCalendar.CurrentDate And DemSupFields.EndTime >= jtlSched.DropDownCalendar.CurrentDate)