dongzao4503 2010-05-08 21:36
浏览 111
已采纳

从时间戳超过一天的MySQL表中删除行?

I found the exact same question here.

But it isn't working for me. I've modified it a bit, manipulated it, and I can't figure it out. I'm trying to remove rows that are over a day old. Here is my code:

if (isset($_POST['prune'])) {

    $sql = "DELETE FROM logs WHERE time < date('now', '-1 days')";
    mysql_query($sql);

    echo 'Logs older than one day removed.';    

    }

Fairly simple question I suppose, but its bugging the hell out of me. I would appreciate any help.

In case it makes a difference, the column is a TIMESTAMP type.

EDIT: Apparently I'm an idiot. The question I linked you to relates to SQLite3. So now my question is, how can I do this in MySQL?

  • 写回答

3条回答 默认 最新

  • dongxueji2838 2010-05-08 21:44
    关注

    You can subtract an interval:

    DELETE FROM logs WHERE time < now() - interval 1 day
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?