It depends. As you can imagine, a lot of the more practical books focused on specific technologies are going to be out of date within a few years at most. This is especially true the younger the technology is. Something like Lindy's Law (
https://en.wikipedia.org/wiki/Lindy_effect) probably applies -- the longer a technology has been around, the longer in the future you can expect it to be around. Things like C and SQL are no longer changing that quickly, even though they are still widely used.
That said, there are a lot of "programming" books that are more technology-independent and contain more "timeless" knowledge about the art and craft of programming (and more fundamentally, computer science). If you want to make sure that your purchases stand the test of time, look for those. You can find a lot of them by searching sites like HN, Reddit, and Stack Overflow for lists of the best computer science and software engineering books. A few examples that tend to show up on these lists:
- Bentley, "Programming Pearls"
- Kernighan and Pike, "The Practice of Programming"
- McConnell, "Code Complete"
- Brooks, "The Mythical Man-Month"
- Abelson and Sussman, "Structure and Interpretation of Computer Programs"
- Gamma et al., "Design Patterns"
- Fowler, "Refactoring"
- Kernighan and Ritchie, "The C Programming Language"
just to list a few off the top of my head.