View Single Post
Old 03-21-2004, 12:01 PM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Date and time fuctions in MS Windows is one of the less trivial things I'm affraid.
But here is a nice approach:
Code:
#include <ctime>
#include <iostream>

using namespace std;

time_t timeDate;
struct tm *currDate;

int main()
{
	char yearBuffer[4];

	timeDate = time(0);
	currDate = localtime(&timeDate); //DOS systemcall!
		
	int month = currDate->tm_mon+1;
	int day = currDate->tm_mday;
        //int year = currDate->tm_year+1900; //Outputs: 2004 
	strftime( yearBuffer, 4, "%y", currDate ); //Output: 04 (instead of 2004)

	cout<<day<<" "<<month<<" "<<yearBuffer<<endl;

	return 0;
}
Just a little hint for the upcoming programmer FWIW:
The first thing is clarity. Check out this:
Quote:
Date set to 1.
What is this?
Val: 'What is the date today?'
Alex: 'Today is 1'.
Val: 'Huh? What was the date of yesterday or the day before yesterday then?'
Alex: '...'

Do you see what I mean?
GL HF!
__________________
Valmont is offline   Reply With Quote