Brain Pickings has a smart piece about research into how long it takes us to form a habit:
When he became interested in how long it takes for us to form or change a habit, psychologist Jeremy Dean found himself bombarded with the same magic answer from popular psychology websites and advice columns: 21 days. And yet, strangely — or perhaps predictably, for the internet — this one-size-fits-all number was being applied to everything from starting a running regimen to keeping a diary, but wasn’t backed by any concrete data.
I’ve now got up to write at 5am about, roughly speaking, approximately, 187 bastard times, give or take, and it is a habit but I don’t know when it stuck. There are definitely harder days even now, as I think you may have suspected from the subtext there. But it is a habit and it was worth getting, so.
Here’s Brain Pickings’ article and it includes details of the book it all comes from too.