When people go to bed and how long they sleep may affect their risk of developing dementia and cognitive decline, a new study suggests.