Limited studies have associated metformin with a reduced risk of viral associated cancers, however these had a number of methodological shortcomings. This study investigated whether the use of metformin is associated with a reduced risk of viral associated cancers in patients with type 2 diabetes. A cohort of 137,754 patients newly-prescribed non-insulin antidiabetic drugs between January 1, 1988 and March 31, 2016 was identified from the UK Clinical Practice Research Datalink and followed until a first-ever diagnosis of a viral associated cancer, death from any cause, end of registration with the practice, or March 31, 2016. Time-varying use of metformin was compared with use of other antidiabetic drugs, with exposures lagged by one year for latency purposes. Time-dependent Cox proportional hazards models were used to estimate adjusted hazard ratios (HRs) with 95% confidence intervals (CIs) of incident viral associated cancer with use of metformin overall, by cumulative duration of use and viral etiology. Overall, there were 424 viral associated cancers during 759,810 person-years of follow-up (crude rate of 5.6 per 10,000 person-years). Metformin was not associated with a decreased rate of viral associated cancer (HR: 0.93, 95% CI: 0.65-1.32). There was no evidence of a duration-response relationship in terms of cumulative duration of use (p trend = 0.69), including with use of metformin for more than 10 years (HR 1.02, 95% CI: 0.52-1.99), or by viral etiology. In this large population-based cohort study, the use of metformin was not associated with a reduced risk of viral associated cancer.