日期比较
最简单的方法,把日期转为时间戳, 直接使用mysql中的 unix_timestamp("时间或者列")函数
SELECT b.end_time as "原合同",a.end_time as "续租合同",b.quit_action,b.contract_no,a.* from contracts a,
(SELECT * from contracts) b WHERE a.ref_id=b.id and b.end_time>=a.end_time and a.customer_type
not IN ("protocol","protocolstaff") and UNIX_TIMESTAMP(a.sign_time)
日期加法(指定日期间隔)
调用mysql的date_add()函数
date 参数是合法的日期表达式。expr 参数是您希望添加的时间间隔。
SELECT b.end_time as "原合同",a.end_time as "续租合同",a.sign_action,b.finish_time,b.quit_action,b.contract_no,a.ref_id,a.id,a.* from contracts a,(SELECT * from contracts) b WHERE a.ref_id=b.id and b.end_time>=DATE_ADD(a.end_time,INTERVAL 2 MONTH) and a.customer_type not IN ("protocol","protocolstaff") and UNIX_TIMESTAMP(a.sign_time)
日期减法(指定日期间隔)
调用mysql date_sub()函数,方法同上