I'm writing a header file for a class project and one of the functions we have to add finds a patient's age from their birth date.

I need to write the function without arguments or any user input and can't use a static date.

I've figured out enough that I have to use the time( ) function to get the current system date I read somewhere that using the localtime( ) function I can convert time_t to a struct tm data type which has all it's various components saved as ints. I also know that I have to add 1 to tm_month to get the real int for the month and 1900 to the year since it's actually saved as years since 1900.


What I need to know is, how do I extract these values for use in our function?

We have the date of birth saved as an int MMDDYYY because that's how the prof wants it... we've already broken the d.o.b. into separate mm dd and yyyy components and just need the current month day and year. We need the current date broken into ints so we can simply subtract them to get the age.


we're using windows vista, and the compiler is I think visual compiler 5.0 '97... or something


OR if there is another way to do this other than using time( ) I'd love to know that, someone in another group said they got the current date using three lines of code

Edited 6 Years Ago by viziroth: clearical and grammarical

time_t rawtime;
time(&rawtime);
struct tm* ptm;
ptm=localtime(&rawtime);
int date=ptm->tm_date;
int year=ptm->tm_year;

Comments
you need to use [Code][Code]

time_t rawtime;
time(&rawtime);
struct tm* ptm;
ptm=localtime(&rawtime);
int date=ptm->tm_date;
int year=ptm->tm_year;

thank you,

ptm is point tm?

so it's a pointer?

ok, we're really behind in the class because 3/4 of the class didn't meet the prerequisites... so we didn't officially go over pointers or indirection or memory for that fact...

thus why I just wiki'd the &, *, and -> operators xD


But i think I understand, I just have to replace tm_date with tm_mon and tm_mday


I just hope the prof accepts it since we didn't do it in class.

Edited 6 Years Ago by viziroth: n/a

This question has already been answered. Start a new discussion instead.