[UPHPU] select records with date
Lonnie Olson
lists at kittypee.com
Thu Jan 28 09:54:42 MST 2010
On Thu, Jan 28, 2010 at 6:42 AM, Justin Giboney <jgiboney at gmail.com> wrote:
> See if this logic helps you, it will get you close, you may need to refine it
>
> basically it finds out how many years it has been since the person
> signed up, subtracts 3 from it, then adds that number to the sign up
> date and gets all records after that new date
>
> SELECT * FROM Users u, User_Actions ua
> WHERE u.id = ua.user_id
> AND ua.date >= ADDDATE(u.sign_up_date, INTERVAL (YEAR(NOW()) -
> YEAR(u.sign_up_date)) - 3) YEAR)
Simple simplification here:
SELECT * FROM Users u, User_Actions ua
WHERE u.id = ua.user_id
AND ua.date >= NOW() - INTERVAL 3 YEAR;
This date math syntax is easier to read and understand. It doesn't
require ADDDATE or anything. Just a simple + or -
More information about the UPHPU
mailing list