Some PhD students wait until the very end of their studies to spend three (miserable?) months writing their thesis. Others work in a more gradual way. I spent about 1,5 years on writing (while still finishing up research tasks as well).
To have an idea of which method is most common, I ran a poll on Twitter on this topic.
You can find the wake of this poll here: