使用JOIN选择65年内的日期范围?

时间:2012-01-09 16:22:34

标签: php sql date

晚上好女士们!我试图在一个将发布信息的php发布脚本上提取查询

SELECT  `id`
FROM    `leads`
WHERE   `status` = 'Passed'
  AND   `campaign_id` = '22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'

原始行是

$id_query  =  mysql_query("SELECT  `id` FROM  `leads` WHERE  `status` =  'Passed' AND     'campaign_id' =  '22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'"); 
$id = mysql_fetch_row($id_query); 
echo $id[0]; 

因此我想添加一个日期变量,它将选择超过65年:

BETWEEN (current_date - "DateField") > 365.0 * 65.0

但显然这不起作用。我正在研究使用JOIN并添加

AND 'datesubmitted_c' BETWEEN Date_Add(curDate(), INTERVAL -65 YEARS) AND curDate()'
$id_query  =  mysql_query("SELECT  `id` FROM  `leads` WHERE  `status` =  'Passed' AND     'campaign_id' =  '22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee' AND 'datesubmitted_c' BETWEEN Date_Add(curDate(), INTERVAL -65 YEARS) AND curDate()'");

不确定使用连接是否合适?

2 个答案:

答案 0 :(得分:3)

认为您正在寻找DATE_ADD方法,以便您可以检查范围。类似的东西:

SELECT  *
FROM    mytable
WHERE   _condition_1_
  AND   date_column BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 65 YEAR)

这将检查日期列date_column的日期是否介于今天的日期和65年之后。

答案 1 :(得分:1)

WHERE
  "DateField" BETWEEN Date_Add(curDate(), INTERVAL -65 YEARS) AND curDate()