Poor sleep can affect memory and concentration almost immediately. Anyone who has tried to hold a conversation after a restless night knows how different the next day can feel.
The longer-term relationship between sleep and dementia risk is more complicated. Research has found associations between sleep patterns and cognitive health, but the direction of that relationship is not always clear. It is worth looking at the evidence carefully rather than assuming that poor sleep directly causes cognitive decline.
Some sleep problems are treatable and worth pursuing for their own sake.
Also worth reading: the role of sleep in memory protection.
If those do not help within a few weeks, that is a reason to see a doctor rather than to keep trying harder. Insomnia has effective treatments and cognitive behavioral therapy for insomnia outperforms sleeping tablets over the long run.