PDA

View Full Version : mySQL Date Manipulation of joindate and Today's Date


josiespencer
04-07-2007, 12:29 AM
I just want to create an SQL statement that will produce a list of users whose joindate is greater than or equal to Today's Date. And while I know a little bit about UNIX, mySQL is null. Can anyone tell me what I am am doing wrong, or is it all wrong? Seems like these would be really easy but I can't seem to add the 120 days to joindate correctly:

SELECT username, joindate FROM user WHERE DATE_ADD(joindate, 120) >= UTC_TIMESTAMP();

I have to assume that DATE_ADD isn't valid for adding 120 days to a date or UTC_TIMESTAMP isn't today's date. Or both?

Adrian Schneider
04-07-2007, 12:59 AM
Since it's just an integer column, you can use some simple math to do it: WHERE joindate >= unix_timestamp(now()) - (86400 * 120);The above would select any users who have registered within the past 120 days. Or.... do you want users who registered since midnight? I'm a bit confused by your logic.

josiespencer
04-07-2007, 01:09 AM
That was awesomely fast and totally correct. You can close this thread! This might be a some kind of world record!

Thanks!