Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CTime class

Status
Not open for further replies.

Jastper

Programmer
Oct 4, 2002
13
0
0
GB
I am having trouble using the CTime and CTimespan classes. I need to use them to create an object of this class with my date of birth and then using the ctimespan object subtract the two to give my age,

Does anyone have any code or tips that would help me out?
 
You don't need to use a CTimeSpan object to do this, you can just use two CTime objects and get your age by using the GetYear(), GetMonth() functions etc.

this example is only accurate to the month but you can modify it to be accurate to the day and it should give you an idea of what you need to do:

CTime now(CTime::GetCurrentTime());
CTime birthdate(1972, 5, 28, 0, 0, 0);
int age = now.GetYear() - birthdate.GetYear();
if(now.GetMonth() < birthdate.GetMonth())
age--;

hope this helps

CMR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top