sark9012
sark9012

Reputation: 5737

Checking date from database

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

Upvotes: 1

Views: 139

Answers (2)

Bella
Bella

Reputation: 3217

I believe you are after something like this:

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

Upvotes: 0

jeroen
jeroen

Reputation: 91734

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)";

Upvotes: 2

Related Questions