Use of Todays Date in Predicates

Posts   
 
    
VS
User
Posts: 2
Joined: 28-Jan-2006
# Posted on: 28-Jan-2006 05:19:56   

Hi Folks,

Please forgive me if this issue sounds obvious. I'm still a little bit new to LLBLGEN. Great product by the way. simple_smile

I seemed to have come across a problem with the usage of Today's date in a WHERE clause, when attempting to use predicates. I've been asked not to use stored procedures for any SELECT statements, so I'm using predicates instead.

The Select Statement When I use Microsoft SQL Server Query Analyser, I have the following SELECT statement:


SELECT * 
   FROM customers c
WHERE DATEDIFF( d, c.pending_delete_date, GETDATE() ) > 6

In other words, give me a list of all customers where the difference between the customer pending delete date and todays date is greater than 6 days.

The problem I'm having a bit of trouble constructing the WHERE clause via the use of predicates and expressions in LLBLGEN. I've written the following code (we're using Adapters), but it doesn't appear to be working:


            Dim eLeftOperand As New Expression( DateTime.Now,                                ExOp.Sub, CustomerFields.Pending_delete_date )
            dtCalculatedPendingDateField = CustomerFields.Pending_delete_date.SetExpression( eLeftOperand )

            Dim pCompareValue As New FieldCompareValuePredicate( dtCalculatedPendingDateField, Nothing, ComparisonOperator.GreaterThan, 6 )

            Dim pPredExpression As New RelationPredicateBucket
            pPredExpression.PredicateExpression.Add( pCompareValue )

            Me.oAdapter.FetchEntityCollection( oCustomers, pPredExpression )

I'm not sure if I'm on the right path in regards to the VB.NET code above matching the WHERE clause in the SQL.

Any help would be apreciated.

Many thanks in advance guys.

Cheers

VS

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 28-Jan-2006 10:49:58   

Hi,

Can't the query be used different:

WHERE DateTime.Now.AddDays(-6) < pending_delete_date?

PredicateFactort.CompareValue(FieldIndex.PendingDelete,ComparisonOperator.LessEqual,DateTime.Now.AddDays(-6))

Or am I missing the point?

Greets, Gab