Calculated field to extract time range and calculate average

I need to add a calculated field that includes the average wait time of a call in the morning period from 8am to12pm only, I already have one to calculate this for all connected calls, but I need one just for only that period of hours.

Example ‘answerTime’:

ifelse(isNotNull({queue}) AND (isNotNull({connectedtimestamp}) OR isNotNull({nxt_connectedtimestamp}),
{ringtime},
NULL)

Example Avg answerTime calculation:

ifelse(isNull(avg(answerTime)),“”,
concat(
toString(floor(avg(answerTime)/3600)),“:”,
right(concat(“00”,toString(floor((avg(answerTime)/60))-(floor(avg(answerTime)/3600)*60))),2),“:”,
right(concat(“00”,toString(floor(avg(answerTime)%60))),2)))

You can use extract to check if its >=8 or <=12

ifelse(extract(‘HH’,{connectedtimestamp})>=8 OR extract(‘HH’,{connectedtimestamp})<=12,
{ringtime},
NULL)