Get wainting time and talking time when call has in the queue

Hello

I need to retrieve and store the time when a call enters the queue along with its waiting time and talk time in the database. How do it… ??