Search between times when using datetime datatype

Posts   
 
    
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 24-Dec-2009 17:02:04   

Hello,

I have a slq query like this:

SELECT 
TIME(DATE_FORMAT(DATE,'%H:%i:%s'))AS A, 
DATE AS B 
FROM LOG 
WHERE TIME(DATE_FORMAT(DATE,'%H:%i:%s')) > TIME('15:40:00')
AND 
TIME(DATE_FORMAT(DATE,'%H:%i:%s')) < TIME('16:00:00')

colum A --> my column is datetime datatype. --> select the time from datetime and cast it in to time datatype.

Column B --> original column DATE (datatype: datetime)

Now i have this entity collection where i add this filter.

How do you filter this with llblgen.

IExpression expres = new DbFunctionCall("DATE_FORMAT", new object[] {LogFields.Date, "%H:%i:%s"});

filter.Add(LogFields.Date.SetExpression(expres) >= Convert.ToDateTime(starttijd));

The filter above is not complete.

My question is:

"How do you create this complex filter searching between time starting form datetime datatype ?"

Is this possible ?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Dec-2009 05:52:03   

I'm not sure which line of your query is the problem. I assume is the nested function (TIME and DATE_FORMAT). You can nest DBFunctionCalls:

IExpression dateFormatExp = new DbFunctionCall("DATE_FORMAT", new object[] {LogFields.Date, "%H:%i:%s"});

IExpression timeExp = new DbFunctionCall("TIME", new object[] {dateFormatExp});

filter.Add(LogFields.Date.SetExpression(timeExp) >= Convert.ToDateTime(starttijd))
filter.Add(LogFields.Date.SetExpression(timeExp) >= Convert.ToDateTime(endtijd))
David Elizondo | LLBLGen Support Team
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 26-Dec-2009 01:40:22   

I got it to work

this is how i did it :

                        
IExpression dateFormatExp = new DbFunctionCall("DATE_FORMAT", new object[] { LogFields.Date, "%H:%i:%s" });

IExpression dbTime = new DbFunctionCall("TIME", new object[] { dateFormatExp });

IExpression inputTime = new DbFunctionCall("TIME", new object[] { starttijd });

filtertime.AddWithAnd(LogFields.Date.SetExpression(dbTime) >= inputTime);

(The convert to datetime is wrong in previous post).

But you gave me the tip sunglasses