The longest I've ever worked on a story was ten years and it was a novella that I eventually self published. I loved that story, the character, the whole thing, and I wanted it to be perfect. And now it's the story I'm most proud of.
But the longest I've spent on a novel is three years (I did have chemo treatments and was horribly sick in there, though, so I don't count one of the years).
I never sold that book but it got me an agent.
Mostly it takes me two years to write a book. They are quite long at 130k and I have four kids and a design business, but I also want the piece to be
right.
The shortest amount of time I've taken was six months.
And I'm now writing on a deadline of six months for a series, so I needed to speed up my process. You always need to be flexible and get your abilities to the point where you can stretch them. But if you can spend the time to create the perfect world, the perfect story, then take it!
I do have to say, though, that working on many many book-length stories over the years has been a great learning experience for me. When I started writing people always said,
Well, you'll never sell your first book (which upset me to no end, because I loved that thing). In my case they were sadly right, but many of my friends sold their first manuscripts so it's not true of everyone. I, however, needed to keep going because it wasn't until my seventh manuscript that I sold.