tags:

views:

32

answers:

2

Hey, I am looking to produce a function where I check the date is in the last fortnight. This is something I have never done before.

I have produced a mysql_query

$q = "SELECT date_subbmited FROM ".TBL_CONF_RESULTS." WHERE home_user = '$u' OR away_user = '$u'";

That would select the date and in PHP i could check whether it was in the last fornight?

Or I could check within the SQL if the date was within the last fornight?

Whats the best practice here? And how would I go about doing this?

date_submitted is the date i want to check, and $u is just the username.

Thanks

+2  A: 

Take a look at DATE_SUB().

Example:

$q = "SELECT date_subbmited FROM ".TBL_CONF_RESULTS." WHERE (home_user = '$u' OR away_user = '$u') AND date_subbmited >= DATE_SUB(CURDATE(),INTERVAL 14 DAY)";
jeroen
A: 

I believe you are after something like this:

SELECT date_submitted FROM table
WHERE date_submitted >= DATE_SUB( CURDATE(), INTERVAL 2 WEEK )
DRL