Is there an easy way to convert date/datetime to a float representing year? I.e. f(2000-01-01) = 2000, f(2015-07-01) ~ 2015.5 and so on. The most obvious method is 2000 + (x - DateTime(2000, 1, 1)) / (DateTime(2001, 1, 1) - DateTime(2000, 1, 1)), but it is only approximate, of course, and becomes more and more wrong for dates far from the reference point (2000 in this case).