Question about elapsed time!

Hi, I have to create a project that tells you the time elapsed.

Let's say you want to now the age of George, we will input his birthday 20/04/2020 and the output will be: 21 years, xyz months, xyzd weeks, ..days, etc..

I don't even know from where to start. I need help, please!
What libraries I should use?
Time can be a deceptively complicated thing to get right. Far from insurmountable, but you need to make sure you get month differences correct, leap years correct. And then account for a lot more stuff if you need to go into hours/minutes/seconds (timezones, daylight savings, etc.)
As far as I know, C++ doesn't really have a built-in feature for time beyond simple things like getting the current date/time.

Since you're asking for libraries, I would recommend Boost libraries to do what the standard library doesn't.

https://www.boost.org/doc/libs/1_42_0/doc/html/date_time/examples.html
https://www.boost.org/doc/libs/1_42_0/doc/html/date_time/examples.html#date_time.examples.time_math
Last edited on
Thanks for you help.
Use mktime() to compute the time_t that corresponds to noon on each of the days.
Subtract one time_t to the other to get the number of seconds between the time_t's.

Divide by 24*60*60 and round off to the nearest integer. This will give you the number of days between the two dates. The logic will work until there are enough leap-seconds to equal a full day, which is likely to be millions of years from now.

http://www.cplusplus.com/reference/ctime/mktime/
Topic archived. No new replies allowed.