convert try..except to if..else
format date on output