$!duration($calc($ticks / 1000))

Hammer used too many !s. I'm not sure why your first script didn't work..looks like $dname didn't do what it should..