It's not just old books that make this claim. For example, in Bello et al., Topics in Contemporary Mathematics, 2007, the authors state
Of course, there are formulas for prime numbers; for example, there is Willans' formula from 1964: Let F(n) = [ cos2 π ((n-1)! + 1)/n ] where [ ... ] denotes the greatest integer function. Then for n ≥ 2, F(n) = 1 iff n is a prime.
Why this doesn't constitute a legitimate formula is anyone's guess, since it uses fairly standard and familiar functions from number theory. But then "formula" has no rigorous definition in mathematics and hence the claim about "no formula for the prime numbers" can't really be addressed until the definitions are made more precise.
Other books refine the claim, saying instead that there is no useful formula for the primes. Of course, the term "useful" is not defined, either. For example, David Wells writes in his 2011 book, Prime Numbers: The Most Mysterious Figures in Math
Well, how could one prove that "a formula is impossible" without giving a more rigorous definition? Yes, it's true that no nonconstant univariate polynomial can take only prime values, but is that really the only kind of formula one would allow? In that case, there is no formula for sine or cosine or exponentials, either!
Writers from the 18th century didn't know about Turing and computability theory, and modern computational complexity theory, so they have an excuse. More modern writers don't. If a "formula" for something means anything at all, it means that the something is computable and the prime numbers are certainly that. (Although I once had the strange obligation of convincing an author of popular math books that it was possible to write a program to compute prime numbers. This author initially denied it was possible, but after an exchange of three or four letters he finally agreed.)
And if a "useful formula" means anything at all, it means what Herb Wilf said it means: that the time to compute the nth object by your useful formula should be an asymptotically negligible fraction of the time to list all n of them. In that sense, also, there is a "useful formula" for the primes -- Lagarias, Miller and Odlyzko showed quite a while ago that the nth prime can be computed in about n½ time.
Can it be done in time polynomial in log n? Nobody knows. Now that's an interesting question. Let's use the language of modern complexity theory to address the really interesting questions about primes and computation, and finally put to rest the silly and embarrassing "no formula for the prime numbers" claim.