在没有用户交互的特定时间后运行SQL查询?

I will take the timestamp enter by a user as $tmp1
and server timestamp as $tmp2
I want to run a mysql query when $tmp1-$tmp2==0
I can do this by user interaction whith server
and check it every time any user login, whether $tmp1-$tmp2==0
but this will require redundant if statement every time .
can it be done using corn jobs or trigger I haven't used them before please help