It is well known that mean-variance portfolio selection is a time-inconsistent optimal control problem in the sense that it does not satisfy Bellman's optimality principle and therefore the usual dynamic programming approach fails. We develop a time- consistent formulation of this problem, which is based on a local notion of optimality called local mean-variance efficiency, in a general semimartingale setting. We start in discrete time, where the formulation is straightforward, and then find the natural extension to continuous time. This complements and generalises the formulation by Basak and Chabakauri (2010) and the corresponding example in Bj\"ork and Murgoci (2010), where the treatment and the notion of optimality rely on an underlying Markovian framework. We justify the continuous-time formulation by showing that it coincides with the continuous-time limit of the discrete-time formulation. The proof of this convergence is based on a global description of the locally optimal strategy in terms of the structure condition and the F\"ollmer-Schweizer decomposition of the mean-variance tradeoff. As a byproduct, this also gives new convergence results for the F\"ollmer-Schweizer decomposition, i.e. for locally risk minimising strategies.