Convert duration to years?
rikki cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 15 00:47:24 PST 2017
On 15/01/2017 9:40 PM, Nestor wrote:
> I cleaned up the function a little, but it still feels like a hack:
>
> uint getAge(uint yyyy, uint mm, uint dd) {
> import std.datetime;
> SysTime t = Clock.currTime;
> ubyte correction = 0;
> if(
> (t.month < mm) ||
> ( (t.month == mm) && (t.day < dd) )
> ) correction += 1;
> return (t.year - yyyy - correction);
> }
>
> Isn't there anything better?
The problem with this is that it won't take into account leap years.
More information about the Digitalmars-d-learn
mailing list