Individual Day, Month, and Year

Nov 30, 2010 at 9:04pm
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
Nov 30, 2010 at 10:12pm
Dec 1, 2010 at 2:24pm
Yes, exactly like that, but i cant figure out how to use it.
Dec 1, 2010 at 2:28pm
I suggest to read about the ten (wow, only ten) functions that are mentioned in the left navbar ;)... self-explanating...
Dec 1, 2010 at 2:34pm
Not really, i am VERY new to this.
Dec 1, 2010 at 2:40pm
You need to be more specific on your problem to get a more specific answer.
( most functions in the reference show code examples )
Dec 1, 2010 at 2:49pm
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.
Dec 1, 2010 at 2:53pm
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.
Dec 1, 2010 at 3:01pm
Thanks,

But for some reason, the 'year' displays '110' and not '2010'.
Dec 1, 2010 at 3:07pm
you must be added to the year.

cout << "year = " << timePtr->tm_year + 1900 << endl;
Last edited on Dec 1, 2010 at 7:25pm
Topic archived. No new replies allowed.