0

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?

shams
  • 124
  • 10
  • what abaut save the creation time on database and just do on select `now()-row_time` ? – Melon Jan 21 '14 at 10:33
  • thanks mate but in mysql is there a way like the same i have asked? thanks in advance – shams Jan 21 '14 at 10:35
  • maybe but if its can be done the way u asked, think abaut the cost of update all rows of the table every minute. i still think you shuld do : `select now()-row_time from your_table;` – Melon Jan 21 '14 at 10:37
  • the problem is i want to save the time for a particular time zone i dont know how to change the time zone in mysql – shams Jan 21 '14 at 11:04
  • [googleit](http://bit.ly/LA3kPa) – Melon Jan 21 '14 at 11:08

1 Answers1

1

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;
Shivam
  • 702
  • 2
  • 10
  • 25