Convert duration to years?

Nestor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 14 19:43:32 PST 2017


Hi,

I would simply like to get someone's age, but I am a little lost 
with time and date functions. I can already get the duration, but 
after reading the documentation it's unclear to me how to convert 
that into years. See following code:

import std.stdio;

void getAge(int yyyy, int mm, int dd) {
   import std.datetime;
   SysTime t1 = SysTime(Date(yyyy, mm, dd));
   SysTime t2 = Clock.currTime();
   writeln(t2 - t1);
}

int main() {
   try
     getAge(1980, 1, 1);
   catch(Exception e) {
     writefln("%s.\n(%s, line %s)", e.msg, e.file, e.line);
   }
}

Notice getAge should return ubyte instead of void, only I haven't 
been able to find how to do it. Any suggestion would be welcome.

Thanks in advance.


More information about the Digitalmars-d-learn mailing list