如何在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?
我创建了一个帖子表。 我想在表格中有一个时间字段,它会随着时间自动更新。 比如说如果帖子在下午1点连续插入并且我在2小时后检查它应该包含值2或类似的东西。 p>
在插入帖子时它将会 包含0分钟。 30分钟后,如果我执行一个选择查询,它应该包含30 p>
有没有办法只在mysql中执行此操作? p> div>
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;