douyi6922
2014-01-21 10:32
浏览 121
已采纳

如何在mysql中创建自动更新时间字段?

I have created a post table. I want to have a time field in the table which will auto update in self with the time. Like say if the post is inserted in a row at 1pm and I am checking it after 2hrs it should contain the value 2 or something like that.

At the time of inserting the post it will contain 0 minutes. After 30 minutes if i execute a select query it should contain 30

Is there a way to do that in mysql only?

图片转代码服务由CSDN问答提供 功能建议

我创建了一个帖子表。 我想在表格中有一个时间字段,它会随着时间自动更新。 比如说如果帖子在下午1点连续插入并且我在2小时后检查它应该包含值2或类似的东西。

在插入帖子时它将会 包含0分钟。 30分钟后,如果我执行一个选择查询,它应该包含30

有没有办法只在mysql中执行此操作?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhi4056 2014-01-21 10:39
    已采纳

    Hey first you just save your time time in table on inserting time with NOW() sql function and when you run the select query just subtract table insert time from NOW(). it will work.

    select NOW() - inserttiontime from table;
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题