Custom wp_trim_words() function not trimming right

What about using this function in functions.php:

function new_excerpt_length($length) {
    return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

And then getting it by adding<?php the_excerpt()?> to php template?

OR:

<?php $string = get_the_excerpt(); if (strlen($string) <=20) {echo '' . $string . '';} else {echo '' . substr($string, 0, 20) . '...';}?>

In this case 20 is characters