Aims: To examine the feasibility and validity of obtaining International Classification of Primary Care (ICPC)-coded diagnoses of diabetes mellitus (DM) from general practice electronic health records for case definition in epidemiological studies, as alternatives to self-reported DM. Methods: The Netherlands Epidemiology of Obesity study is a population-based cohort study of 6671 persons aged 45–65 years at baseline, included between 2008−2012. Data from electronic health records were collected between 2012−2014. We defined a reference standard using diagnoses, prescriptions and consultation notes and investigated its agreement with ICPC-coded diagnoses of DM and self-reported DM. Results: After a median follow-up of 1.8 years, data from 6442 (97%) participants were collected. With the reference standard, 506 participants (79/1000 person-years) were classified with prevalent DM at baseline and 131 participants (11/1000 person-years) were classified with incident DM during follow-up. The agreement of prevalent DM between self-report and the reference standard was 98% (kappa 0.86), the agreement between ICPC-coded diagnoses and the reference standard was 99% (kappa 0.95). The agreement of incident DM between ICPC-coded diagnoses and the reference standard was >99% (kappa 0.92). Conclusions: ICPC-coded diagnoses of DM from general practice electronic health records are a feasible and valid alternative to self-reported diagnoses of DM.