开发者

Checking date from database

开发者 https://www.devze.com 2023-01-07 10:55 出处:网络
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 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 for开发者_如何学Gonight?

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


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


I believe you are after something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号