Search code examples
c#nhibernateselecthqlnhibernate-3

NHibernate get next Birthdays


I have a table which contains a column Birthday of Type DateTime. Now I should select with HQL all Persons which Birthday is in the next 10 days or was in the last 5 days. How can I do this with NHibernate 3.2 HQL? Thanks. Thomas


Solution

  • I have solved it with

    var result =
    session.CreateQuery(@"from Person 
                          where 1 = (FLOOR(DATEDIFF(dd,Birthday,GETDATE()+10) / 365.25))
                                        -
                                    (FLOOR(DATEDIFF(dd,Birthday,GETDATE()-5) / 365.25))")
           .List<Person>();