Individual Day, Month, and Year

Hi,

I need a way to, using the time.h library, send the day of month to one variable ("day1"), the number of the month ("month1"), and the year ("year1").

Can anyone help me?

Thanks,
Stephen
Yes, exactly like that, but i cant figure out how to use it.
I suggest to read about the ten (wow, only ten) functions that are mentioned in the left navbar ;)... self-explanating...
Not really, i am VERY new to this.
You need to be more specific on your problem to get a more specific answer.
( most functions in the reference show code examples )
Ok, my problem is this:

I have a program that calculates your age in days, and at the moment, you need to manually enter in the current date, AS WELL AS your birth date. I want to be able to pull the system date, and use that instead of having to enter it in manually. I need the individual date segments (month, day, year (all 4 digits)) in individual variables (month in 'month1', day in 'day1', year in 'year1'), and I cant figure out how to do it.
example:

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

int main()
{
	time_t t = time(NULL);
	tm* timePtr = localtime(&t);

  cout << "seconds= " << timePtr->tm_sec << endl;
  cout << "minutes = " << timePtr->tm_min << endl;
  cout << "hours = " << timePtr->tm_hour << endl;
  cout << "day of month = " << timePtr->tm_mday << endl;
  cout << "month of year = " << timePtr->tm_mon << endl;
  cout << "year = " << timePtr->tm_year << endl;
  cout << "weekday = " << timePtr->tm_wday << endl;
  cout << "day of year = " << timePtr->tm_yday << endl;
  cout << "daylight savings = " << timePtr->tm_isdst << endl;
}


hope this is what you were looking for.
Thanks,

But for some reason, the 'year' displays '110' and not '2010'.
you must be added to the year.

cout << "year = " << timePtr->tm_year + 1900 << endl;
Last edited on
Topic archived. No new replies allowed.