ObjectiveTo examine associations of sleep duration and quality with cognitive impairment in older adults and the moderating role of gender and age in these associations.MethodsThis community-based cross-sectional study included 4,837 participants aged 60 years and above. Cognitive function was assessed using the Chinese version of the Mini-Mental State Examination (MMSE), and the participants were grouped based on the presence of cognitive impairment. The duration and quality of sleep were assessed using the Pittsburgh Sleep Quality Index (PSQI). Multivariate logistic regression models were used to analyze associations of sleep duration and quality with cognitive impairment. The role of age and gender in these associations have also been explored.ResultsThe age (mean ± SD) of the participants was 71.13 ± 5.50 years. Of all older adults, 1,811 (37.44%) were detected as cognitive impairment, and 1755 (36.8%) had poor sleep quality. Among those with cognitive impairment, 51.09% were female. The proportion of the participants with cognitive impairment is significantly higher in those with symptoms of depression (49.73%, 273/549) (χ2 = 41.275, p < 0.001) than in those without depressive symptoms. After adjustment for multiple confounding factors and the crucial covariate (depressive symptoms), the odds ratios (OR) (95% confidence interval [CI]) of cognitive impairment (with 7–7.9 h regarded as the reference group) for individuals with a sleep duration of <6, 6–6.9, 8–8.9, and ≥ 9 h were 1.280 (1.053–1.557), 1.425 (1.175–1.728), 1.294 (1.068–1.566), and 1.360 (1.109–1.668), respectively. Subgroup analysis showed a V-shaped association between night sleep duration and cognitive impairment in males (p ≤ 0.05), and the association was stronger for individuals aged 60–80 years. With regard to sleep quality, the fully adjusted OR (95%CI) of cognitive impairment were 1.263 (1.108–1.440). According to scores of subscales in the PSQI, daytime dysfunction was associated with an increased risk of cognitive impairment (OR: 1.128, 95%CI: 1.055–1.207). Subgroup analysis also revealed a statistically significant correlation between poor sleep quality (including daytime dysfunction) and cognitive impairment in different gender and age groups, with the association being stronger in females (OR: 1.287, 95%CI: 1.080–1.534) and those aged 81–97 years (OR: 2.128, 95%CI: 1.152–3.934). For cognitive impairment, the group aged 81–97 years with daytime dysfunction was associated with a higher odds ratio than other age groups.ConclusionThe present study showed that inadequate or excessive sleep was associated with cognitive impairment, especially in males, who exhibited a V-shaped association. Cognitive impairment was also associated with poor sleep quality as well as daytime dysfunction, with females and individuals aged 81–97 years exhibiting the strongest association.