Birthday filter

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 03-Apr-2010 15:00:22   

Hi, i am trying to write a filter that ll get me the list of users whose birthday is this week (between today and 7 days from today).

the entity is user and the field is birthday.

i dont know how to use dayofyear with userfields.birthday.

any ideas? thanks

-shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Apr-2010 22:18:06   

What would you do in sql? For instance, if you are looking for this:

SELECT * 
FROM Users
WHERE Birthday BETWEEN GETDATE() AND DATEADD(dd, 7,  GETDATE())

then this is an approximate code (assuming Adapter):

UserCollection users= new UserCollection();

IExpression funcGetDate = new DbFunctionCall("GETDATE", new object[] {});
IExpression funcDateAdded = new DbFunctionCall("DATEADD(dd, 7, {0})", new object[] {funcGetDate});

IPredicateExpression filter = new PredicateExpression(
    new FieldBetweenPredicate(UserFields.Birthday,
           UserFields.Birthday.SetExpression(funcGetDate), 
           UserFields.Birthday.SetExpression(funcDateAdded)));

users.GetMulti(filter);

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 05-Apr-2010 02:03:57   

David, thanks for the answer but birthdate can not be between todays date and 7 days from now. i know i have to use dayofyear but i dont know how to use it as a predicate expression.

using self servicing.

-shane

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-Apr-2010 10:42:57   

i am trying to write a filter that ll get me the list of users whose birthday is this week (between today and 7 days from today).

Are you working in Facebook smile

the entity is user and the field is birthday. i dont know how to use dayofyear with userfields.birthday.

Do you know the SQL statement you ned to execute? If so would you please post it here.

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 05-Apr-2010 14:52:18   

Walaa wrote:

i am trying to write a filter that ll get me the list of users whose birthday is this week (between today and 7 days from today).

Are you working in Facebook smile

no, not in facebook simple_smile it is an application to track student birthdays.

the entity is user and the field is birthday. i dont know how to use dayofyear with userfields.birthday.

Do you know the SQL statement you ned to execute? If so would you please post it here.

i guess it ll be something like:

datepart(dy,BirthDate) between datepart(dy,GETDATE()) and datepart(dy,GETDATE()) + 7

-shane

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-Apr-2010 15:12:29   

This is easier done with Linq (if it's an option). If so, please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=16737

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 05-Apr-2010 17:18:58   

Walaa wrote:

This is easier done with Linq (if it's an option). If so, please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=16737

unfortunately i dont use linq yet.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Apr-2010 06:08:18   

e106199 wrote:

David, thanks for the answer but birthdate can not be between todays date and 7 days from now. i know i have to use dayofyear but i dont know how to use it as a predicate expression.

I thought it should work that way simple_smile Anyway, here you go with an approximate code for what you are looking for (without linq):

UserCollection users = new UserColletions();

IExpression funcGetDate = new DbFunctionCall("GETDATE", new object[] {});
IExpression betweenStart = new DbFunctionCall("DATEPART(dy, {0})", new object[] {funcGetDate});
IExpression betweenEnd =  new Expression(betweenStart, ExOp.Add, 7);
EntityField2 betweenLeftOp = UserFields.BirthDate.SetExpression(
    new DbFunctionCall("DATEPART(dy, {0})", new object[] {UserFields.BirthDate}));

IPredicateExpression filter = new PredicateExpression(
    betweenLeftOp >= betweenStart & betweenLeftOp <= betweenEnd );

users.GetMulti(filter);
David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 15-Apr-2010 17:13:03   

decided on using a computed field that will return 0 or 1 depending on the match.

way easier that way simple_smile

thanks -shane