It’s a very hard thing to know when to give up a project. Sometimes, when you’re working on a project that isn’t going right for technical or other reasons, it’s best to give up instead of wasting more and more money and time trying to get it to work. But it’s tough deciding when that time has come, and it’s very hard to stop working on something that you’ve already put loads of effort into.
The longest I’ve spent working on a project that I had to give up on was about half a year.
It would depend on the project and how I feel about it. I would spend as much time as needed to know whether or not it is possible. At the moment, I have a limited amount of time to do my PhD, so I don’t want to waste time on something that is unlikely to get results. Perhaps in the future I can work on some riskier, high-payoff, low-viability research.
Some people spend 3 or 4 years (or more!) on their PhD project without giving up!
It depends on the problem, and if it seems as though there is no scientific worth to be had in following it through. Remember, negative results are still scientifically important, because learning what doesn’t work is just as important as learning what does.
As long as I have money to work on it, unless what I am investigating has already being discovered by somebody else (one of the biggest fears for scientists: being scooped!) or unless it has given enough negative results that are disproving my hypothesis. In these cases keeping going on this project, would be a waste of time