STR_TO日期不太合适

时间:2012-10-30 12:25:51

标签: mysql datetime

Select *,  STR_TO_DATE(l.act_detail,'%Y-%m-%d %H:%i:%s') AS callback_date, DATE_FORMAT(l.act_date , '%m/%d/%Y %H:%i' ) as activity_date                   
            from lead_activity as l 
            join rawdata as r on (r.phone=l.phone) && (r.year_make=l.year_make) && (r.model=l.make)   
            where l.sp_id=".$_SESSION['user']['sp_id']." 
            and ((callback_date>='$date1' ) && (callback_date<= '$date2')) 
             and l.act_name='SCB'
            ORDER BY  l.act_date DESC

我正在尝试使用转换为datetime的文本文件并在该列上执行操作?有任何想法吗 ? act_detail = 2012-10-29 05:10:00

1 个答案:

答案 0 :(得分:0)

  • 您不应该使用callback_date,因为它是别名,您不能在where子句
  • 中使用它
  • 您无法使用&&,而是使用AND

查询,

SELECT .....
FROM ....
WHERE  l.sp_id= 'sessionValue' AND
       (STR_TO_DATE(l.act_detail,'%Y-%m-%d %H:%i:%s') >= '$date1') AND
       (STR_TO_DATE(l.act_detail,'%Y-%m-%d %H:%i:%s') <= '$date2') .....