SELECT 所有 30 天前的记录

2021-12-10 00:00:00 perl mysql

我需要选择所有 30 天前的记录.我有下面的代码,但它不起作用.在 updatestatus 中,我的日期是 12/26/2011.我创建了一个 30 天的日期,例如

I need to SELECT all records that are 30 days old. I have the code below but it's not working. In updatestatus I have dates like 12/26/2011. I create a 30 day old date like

$onemonthago="01/01/2012";
$sth = $dbh->prepare(qq(
        SELECT * 
        FROM people 
        WHERE STR_TO_DATE (updatestatus,'%m/%d/%y') 
              <= STR_TO_DATE ( "$onemonthago",'%m/%d/%Y')
                    )  );

推荐答案

这是我用的.很简单

$sth = $dbh->prepare(qq(SELECT * FROM people WHERE updatestatus + INTERVAL 30 DAY <=     NOW() )) or die $DBI::errstr;

相关文章