在php中使用mysql date_sub(now(),interval 1 day)的替代方法


Alternate method to use mysql date_sub(now(),interval 1 day) in php?

在php中使用mysql date_sub(now(),interval 1 day)的替代方法?

实际上我想要这个替代方案,因为在zend where子句第二个参数是date_sub函数,它将其作为字符串。下面显示了确切的查询

->where("FROM_UNIXTIME(qnas.cdate,'%Y-%m-%d %h:%i:%s')>?" ,"date_sub(now(),interval 1 day)");

第二个参数date_sub(now(),interval 1 day)是mysql函数,用于显示大于前一天日期的记录

->where("FROM_UNIXTIME(qnas.cdate,'%Y-%m-%d %h:%i:%s') > DATE_SUB(NOW(), INTERVAL 1 day)");

如果该值不是用户提供的参数,那么将其绑定为用户提供的参数是没有意义的。只需将其写入查询。此外,如果您的cdate列是任何类型的日期/时间列,则不需要FROM_UNIXTIME转换。