从当前日期的最后(3,4,5)天插入的mysql中选择记录

时间:2015-07-08 05:16:18

标签: php mysql sql

从当前日期(3,4,5)天插入的mysql中选择记录

示例:从tbl中选择id,其中date(created)IN(3,4,5)

select JOB_TBL_ID from job_post where DAYOFMONTH(date(CREATED)) IN (3,4,15) 

TBL:job_post

''''''''''''|'''''''''''''''''''''''''''|
JOB_TBL_ID  |  CREATED                  |
'''''''''''''|'''''''''''''''''''''''''''''
1            |2015-07-01 18:06:32
2             2015-06-30 19:14:42     

2 个答案:

答案 0 :(得分:0)

您可以像这样使用DATEDIFF功能

select id from tbl where DATEDIFF(CURDATE(),date(created)) IN (3,4,15,7,8)

答案 1 :(得分:0)

代码不是完美的。只有在没有其他解决方案满足您的情况下才选择此项。

$condition='';
foreach($YOUR_SELECTED_DATES as $value)
{
  if($condition!='')
      $condition.=" OR ";
  $condition.=" date(CREATED) = ( CURDATE() - INTERVAL ".$value." DAY ) ";
}

$your_qry="select JOB_TBL_ID from job_post where ".$condition;