SELECT 所有 30 天前的记录 [英] SELECT all records that are 30 days old

查看:42
本文介绍了SELECT 所有 30 天前的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要选择所有 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;

这篇关于SELECT 所有 30 天前的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆