On Sat, Feb 10, 2024 at 03:53:09PM +0000, Alexander Zhirov via Digitalmars-d-learn wrote: > Is it possible to calculate the difference between dates in years > using regular means? Something like that > > > ``` > writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); > ``` > > At the same time, keep in mind that the month and day matter, because > the difference between the year, taking into account the month that > has not come, will be less. > > My abilities are not yet enough to figure it out more elegantly.
IIRC you can just subtract two DateTime's to get a Duration that you can then convert into whatever units you want. Only thing is, in this case conversion to months may not work because months don't have a fixed duration (they can vary from 28 days to 31 days) so there is no "correct" way of computing it, you need to program it yourself according to the exact calculation you want. T -- PNP = Plug 'N' Pray