The real answer is the uninformative, "it depends".
A friend of mine wrote a book that went from initial concept to publication in one month. I've heard of writers taking decades to write a book.
I've self-published three books, all non-fiction. In my case, for each book I spent 2 or 3 months doing research and getting notes together, than about a year turning those notes into a book, perhaps a month getting someone to proofread it and making updates, and then a few weeks going through the mechanics of getting it published.
Self-publishing will almost always be faster than traditional publishing, because you don't have to spend time finding a publisher who is interested in your book, and go through additional cycles of their edits and requested changes. I've written free-lance magazine articles where I spent considerable time sending them off to various potential markets and then having to just sit around and wait for their replies.
Getting words on paper and going through editing cycles is normally the long pole in the tent, and how long you spend on that is mostly up to you. If you have a full time job and kids to take care of, finding time to work on your book may be a big challenge, and it could take you years. If you have nothing else to do but sit and write, and you have the discipline to do it, then like my friend you may get a book together in a month. (She had a job, but she was president of the organization and the book was related to her job, so she basically just made it her priority for a month.)