On Sunday, 15 January 2017 at 07:25:26 UTC, rikki cattermole wrote:
So I had a go at this and found I struggled looking at "magic" functions and methods.
Turns out there is a much simpler answer.

int getAge(int yyyy, int mm, int dd) {
  import std.datetime;
  auto t1 = cast(DateTime)SysTime(Date(yyyy, mm, dd));
  auto t2 = cast(DateTime)Clock.currTime();

  int numYears;
  while(t2 > t1) {
     t1.add!"years"(1);
     numYears++;
  }

  return numYears;
}


Well... correct me if I am wrong, but isn't t1.add!"years"(1) simply adding one year to t1?

Reply via email to