In the United States, cannabis is increasingly used to manage chronic pain. Veterans Health Administration (VHA) patients are disproportionately affected by pain and may use cannabis for symptom management. Because cannabis use increases the risk of cannabis use disorders (CUDs), we examined time trends in CUD among VHA patients with and without chronic pain, and whether these trends differed by age. From VHA electronic health records from 2005 to 2019 (∼4.3-5.6 million patients yearly), we extracted diagnoses of CUD and chronic pain conditions (International Classification of Diseases [ICD]-9-CM, 2005-2014; ICD-10-CM, 2016-2019). Differential trends in CUD prevalence overall and age-stratified (<35, 35-64, or ≥65) were assessed by any chronic pain and number of pain conditions (0, 1, or ≥2). From 2005 to 2014, the prevalence of CUD among patients with any chronic pain increased significantly more (1.11%-2.56%) than those without pain (0.70%-1.26%). Cannabis use disorder prevalence increased significantly more among patients with chronic pain across all age groups and was highest among those with ≥2 pain conditions. From 2016 to 2019, CUD prevalence among patients age ≥65 with chronic pain increased significantly more (0.63%-1.01%) than those without chronic pain (0.28%-0.47%) and was highest among those with ≥2 pain conditions. Over time, CUD prevalence has increased more among VHA patients with chronic pain than other VHA patients, with the highest increase among those age ≥65. Clinicians should monitor symptoms of CUD among VHA patients and others with chronic pain who use cannabis, and consider noncannabis therapies, particularly because the effectiveness of cannabis for chronic pain management remains inconclusive.