Stuart-campbell / RushOrm

Object-relational mapping for Android
http://www.rushorm.co.uk/
Other
172 stars 19 forks source link

How to find if saved date field value is in between date range #100

Closed permadart closed 5 years ago

permadart commented 8 years ago

Hello. I have a String saving a date in my db.

I have this SQL working on my remote db

SELECT * FROM user_meals WHERE CURDATE() BETWEEN date_of_meal AND DATE_ADD(date_of_meal, INTERVAL 14 DAY) AND email = '$email' ORDER BY date_of_meal DESC LIMIT 1

Is there a way I could achieve the same with RushORM for my local db?

Stuart-campbell commented 8 years ago

Hi,

Almost all can be done via RushSearch only thing you have to do is actually create the date objects you want to search between.

Date now = new Date();
Date in14Days = // TODO
UserMeals userMeal = new RushSearch()
    .whereBefore("date_of_meal", in14Days)
    .and()
    .whereAfter("date_of_meal", now)
    .and()
    .whereEqual("email", email)
    .limit(1)
    .orderDesc("date_of_meal")
    .findSingle(UserMeals.class);

Note I have written this free hand do double check the logic.

Cheers

permadart commented 8 years ago

Thanks again, man. Will try it ASAP.

Cheers!