current date for function

I need to find the current date and use it in a function, not display it. Everything I found so far just displays the current date and will not let me use it to do my calculation. If I can find out the current year, month, and day separately would also work.

My function needs to find a person’s age from the input of their date of birth. The input and output has to be in the integer format.
Example of input data: (12052010) format- “mmddyyyy”

I already have it broken down into: 12 , 05, 2010 separately so I can do the math to find out their age.

I’m using Microsoft Developer Studio - Visual C++ 5.0
Any help will be appreciated, thanks
please share your code with us.
if i can,i will help you.
You should access to COleDateTime. Take a look at that.
Not sure it will help, but here is some of the code I'm working with.

int studentDateOfBirth = 02151971; //(student input)
int month;
int day;
int year;

// Function to print the student’s date of birth with dashes.
void studentInformation::getPatientDateOfBirth( )
{
month = studentDateOfBirth / 1000000;
day = (studentDateOfBirth % 1000000) / 10000;
year = studentDateOfBirth % 10000;

birthDate = Date(month,day,year);
birthDate.writeShortDate();
}

// Function needs to return the patient’s age.
int StudentInformation::getStudentAge( )
{

return
}
Last edited on
All the standard C and C++ time functions are found in <ctime>
http://www.cplusplus.com/reference/clibrary/ctime/

To find what you want, just get the current time(), and convert it to the localtime().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <ctime>
#include <iostream>
using namespace std;

const char* MONTHS[] =
  {
  "January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
  };

int main()
  {
  time_t     rawtime;
  struct tm* timeinfo;

  time( &rawtime );
  timeinfo = localtime( &rawtime );

  cout << "Today's date is "
       << timeinfo->tm_mday << " "
       << MONTHS[ timeinfo->tm_mon ] << " "
       << (timeinfo->tm_year + 1900) << ".\n";

  return 0;
  }

Make sure to pay attention to the documentation for the fields in the tm structure.
http://www.cplusplus.com/reference/clibrary/ctime/tm/

Hope this helps.
Topic archived. No new replies allowed.